Created
October 17, 2016 15:25
-
-
Save mikhailramalho/df4f94e674906355ae2874d98caae7c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
#include <assert.h> | |
float my_nextafterf( float from, float to ) | |
{ | |
union { | |
float a; | |
int b; | |
} from_union = { .a = from }; | |
if(from > to) | |
from_union.b--; | |
else | |
from_union.b++; | |
return from_union.a; | |
} | |
int main(void) | |
{ | |
float from = 1; | |
float to = my_nextafterf(from, 2); | |
printf("%.64f (%a)\n", to, to); | |
assert(to == 0x1.000002p+0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment