fenv

Floating point exceptions - gcc bug?

▼魔方 西西 提交于 2019-12-10 17:27:39
问题 Consider the following code: #include <fenv.h> #include <stdio.h> int main() { #pragma STDC FENV_ACCESS ON 1.0/0.0; printf("%x\n", fetestexcept(FE_ALL_EXCEPT)); } I would expect it to print a nonzero value corresponding to FE_DIVBYZERO , but it prints 0. Changing the second line of main to double x = 1.0/0.0; gives the expected behavior. Is this permitted, or is it a bug? Edit: For what it's worth, at first it may seem that in most real-world code, the operations which might cause fenv

Does FENV_ACCESS pragma exist in C++11 and higher?

南楼画角 提交于 2019-12-01 09:42:55
Reading a bug report for clang not supporting FENV_ACCESS pragma I've come across a comment : Setting the rounding mode without using #pragma STDC FENV_ACCESS ON invokes undefined behavior. See C11 7.6.1/2. (This pragma does not exist in C++, so <cfenv> is unusable, but that's not our fault...) Does this pragma really not exist in C++, rendering <cfenv> unusable? I've tried to search for it in the C++11 standard, but it really isn't mentioned at all. Are pragmas inherited from C along with function prototypes? Or are they actually not needed to avoid UB, since the C++ standard doesn't say

Adding two floating-point numbers

孤街浪徒 提交于 2019-11-27 23:31:53
I would like to compute the sum, rounded up, of two IEEE 754 binary64 numbers. To that end I wrote the C99 program below: #include <stdio.h> #include <fenv.h> #pragma STDC FENV_ACCESS ON int main(int c, char *v[]){ fesetround(FE_UPWARD); printf("%a\n", 0x1.0p0 + 0x1.0p-80); } However, if I compile and run my program with various compilers: $ gcc -v … gcc version 4.2.1 (Apple Inc. build 5664) $ gcc -Wall -std=c99 add.c && ./a.out add.c:3: warning: ignoring #pragma STDC FENV_ACCESS 0x1p+0 $ clang -v Apple clang version 1.5 (tags/Apple/clang-60) Target: x86_64-apple-darwin10 Thread model: posix $

Adding two floating-point numbers

天涯浪子 提交于 2019-11-26 21:33:56
问题 I would like to compute the sum, rounded up, of two IEEE 754 binary64 numbers. To that end I wrote the C99 program below: #include <stdio.h> #include <fenv.h> #pragma STDC FENV_ACCESS ON int main(int c, char *v[]){ fesetround(FE_UPWARD); printf("%a\n", 0x1.0p0 + 0x1.0p-80); } However, if I compile and run my program with various compilers: $ gcc -v … gcc version 4.2.1 (Apple Inc. build 5664) $ gcc -Wall -std=c99 add.c && ./a.out add.c:3: warning: ignoring #pragma STDC FENV_ACCESS 0x1p+0 $