Skip to content

Instantly share code, notes, and snippets.

@shirok
Last active May 14, 2016 03:24
Show Gist options
  • Save shirok/295a78c9864c1fd6e6ac673b33ff13c1 to your computer and use it in GitHub Desktop.
Save shirok/295a78c9864c1fd6e6ac673b33ff13c1 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
float a(float x)
{
return x + 0.25f - 0.25f;
}
float b(float x)
{
return x - 0.25f + 0.25f;
}
void show(float x)
{
printf("x = %10.10e, a = %10.10e, b = %10.10e\n", x, a(x), b(x));
}
int main()
{
show(ldexpf(1.0f, 22));
show(ldexpf(-1.0f, 22));
show(ldexpf(1.0f, -26));
show(ldexpf(-1.0f, -26));
/* 他の解については http://blog.practical-scheme.net/shiro/20160513-flonum-question 参照 */
}
/*
$ ./a.out
x = 4.1943040000e+06, a = 4.1943037500e+06, b = 4.1943040000e+06
x = -4.1943040000e+06, a = -4.1943040000e+06, b = -4.1943037500e+06
x = 1.4901161194e-08, a = 0.0000000000e+00, b = 1.4901161194e-08
x = -1.4901161194e-08, a = -1.4901161194e-08, b = 0.0000000000e+00
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment