Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange, float type parameter passing in function in windows
    primarykey
    data
    text
    <p>There is a piece of code confuse me, which runs in windows! Here is the code:</p> <pre><code>#define point_float2uint(x) *((unsigned int *)&amp;x) float divide_1000(float y) { float v = y / 1000.0f; return v; } float divide_1000(int y) { float v = float(y) / 1000.0f; return v; } void float_test(void) { int num[5] = {67975500, 67251500, 67540620, 69435500, 70171500}; for (int i = 0; i &lt; 5; ++i) { int a = num[i]; float af_f = divide_1000(float(a)); float af_i = divide_1000((a)); printf("src num:%d, af_f:%f, %x, af_i:%f, %x\n", num[i], af_f, point_float2uint(af_f), af_i, point_float2uint(af_i)); } } </code></pre> <p>Here is the output, compiled by vs2005:</p> <pre><code>src num:67975500, af_f:67975.507813, 4784c3c1, af_i:67975.500000, 4784c3c0 src num:67251500, af_f:67251.507813, 478359c1, af_i:67251.500000, 478359c0 src num:67540620, af_f:67540.625000, 4783ea50, af_i:67540.617188, 4783ea4f src num:69435500, af_f:69435.507813, 47879dc1, af_i:69435.500000, 47879dc0 src num:70171500, af_f:70171.507813, 47890dc1, af_i:70171.500000, 47890dc0 </code></pre> <p>The question is: why I use the "<strong>divide_1000</strong>", get the different result in windows? This is not what I want! And I find that not all the integer result in different, but some just like the code above. </p> <p>Here is the the output, comipled by gcc4.4.5 in debian:</p> <pre><code>src num:67975500, af_f:67975.507812, 4784c3c1, af_i:67975.507812, 4784c3c1 src num:67251500, af_f:67251.507812, 478359c1, af_i:67251.507812, 478359c1 src num:67540620, af_f:67540.625000, 4783ea50, af_i:67540.625000, 4783ea50 src num:69435500, af_f:69435.507812, 47879dc1, af_i:69435.507812, 47879dc1 src num:70171500, af_f:70171.507812, 47890dc1, af_i:70171.507812, 47890dc1 </code></pre> <p>I get the same result in useing different function "<strong>divide_1000</strong>". That's what I want.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload