Author Topic: What is meant by -0.0 ?  (Read 5167 times)

Bitbeisser

• Global Moderator
• Member
• Posts: 761
Re: What is meant by -0.0 ?
« Reply #15 on: March 27, 2013, 04:07:06 pm »
Yet another example:

Ralf

PlezzeR

• Guest
Re: What is meant by -0.0 ?
« Reply #16 on: March 27, 2013, 04:24:46 pm »
More testing
Code: [Select]
`#include <stdio.h>#include <math.h>#define NUM_A "-0.0000000000000000000000000001"int main(int argc, char *argv[ ]){ float a = 1; float a2 = -0.0000000000000000000000000001; double b; a = -10 * (a - a); printf("-10 * (1 - 1) = %e\n", a); a = 0; a = -10 * a; printf("-10 * 0 = %e\n", a); a = a / a; printf("-0 / -0 = %e\n", a); a = -1.0E-28; printf("-1.0e-28 = %f\n", a); printf("-1.0e-28 = %e\n", a); printf(NUM_A" = %f\n", a2); printf(NUM_A" = %e\n", a2); a = powf(a, 2.0); printf("powf(-1.0E-28, 2.0) = %e\n", a); a = powf(a2, 2.0); printf("powf("NUM_A", 2.0) = %e\n", a); a = powf(-1.0E-28, 15.0); printf("powf(-1.0E-28, 15.0) = %e\n", a); a = powf(a2, 15.0); printf("powf("NUM_A", 15.0) = %e\n", a); a = a2 / a2; printf(NUM_A" / "NUM_A" = %e\n", a); a = a2 / 1.0e+30; printf(NUM_A" / 1.0e+30 = %e\n", a); b = a2 / 1.0e+300; printf(NUM_A" / 1.0e+300 = %e\n", b); a = 10 / -INFINITY; printf("10 / -inf = %e\n", a); return 0;}`
Result:
Code: [Select]
`-10 * (1 - 1) = -0.000000e+00-10 * 0 = -0.000000e+00-0 / -0 = nan-1.0e-28 = -0.000000-1.0e-28 = -1.000000e-28-0.0000000000000000000000000001 = -0.000000-0.0000000000000000000000000001 = -1.000000e-28powf(-1.0E-28, 2.0) = infpowf(-0.0000000000000000000000000001, 2.0) = infpowf(-1.0E-28, 15.0) = -infpowf(-0.0000000000000000000000000001, 15.0) = -inf-0.0000000000000000000000000001 / -0.0000000000000000000000000001 = 1.000000e+00-0.0000000000000000000000000001 / 1.0e+30 = -1.000000e-58-0.0000000000000000000000000001 / 1.0e+300 = -0.000000e+0010 / -inf = -0.000000e+00`
Interesting, if compiler Optimizations = None then:
Code: [Select]
`a = a2 / 1.0e+30;printf(NUM_A" / 1.0e+30 = %e\n", a);`
Given the result:
Code: [Select]
`-0.0000000000000000000000000001 / 1.0e+30 = -0.000000e+00`