...
This code attempts to reduce a floating-point number to a denormalized value and then restore the value. This operation is very imprecise.
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h> float x = 1/3.0; printf("Original : %e\n", x); x = x * 7e-45; printf("Denormalized? : %e\n", x); x = x / 7e-45; printf("Restored : %e\n", x); |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h> double x = 1/3.0; printf("Original : %e\n", x); x = x * 7e-45; printf("Denormalized? : %e\n", x); x = x / 7e-45; printf("Restored : %e\n", x); |
Code Block |
---|
Original : 3.333333e-01 Denormalized? : 2.333333e-45 Restored : 3.333333e-01 |
If using doubles also produces denormalized numbers, using long doubles may or may not help. (On some implementations, long double has the same exponent range as double.) If using long doubles produces denormalized numbers, some other solution must be found.
...