Advertisement
homer512

b-a+a <= b failure

Oct 6th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <fenv.h>
  2. #include <math.h>
  3. #include <stdio.h>
  4.  
  5.  
  6. int main(void)
  7. {
  8.   fesetround(FE_UPWARD);
  9.   float smallest = nextafterf(0.f, 1.f);
  10.   float cur, prev;
  11.   for(cur = prev = smallest; cur < HUGE_VALF;
  12.       prev = cur, cur = nextafterf(cur, HUGE_VALF)) {
  13.     if(cur - smallest + smallest > cur)
  14.       printf("Failed %1$g - %2$g + %2$g <= %1$g\n", cur, smallest);
  15.     if(cur - prev + prev > cur)
  16.       printf("Failed %1$g - %2$g + %2$g <= %1$g\n", cur, prev);
  17.   }
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement