Hi! I want to calculate the smallest floating point x such that x+2=x. I've written a programme in C that does not actually determines the smallest floating point x such that x+2=x, but rather determines a power of two within an interval that contains the smallest floating point x. Does anyone have any ideas how can I improve this solution or find out a new one? Is there any built-in function in MATLAB and/or C to get accurate approximations of that x?(adsbygoogle = window.adsbygoogle || []).push({});

Code (Text):#include <stdio.h>

int main( int argc, char **argv )

{

float x = 1.0f;

printf( "current x \t 2 + current x\n" );

do {

printf( "%G\t\t %.20f\n", x, (2.0f + x) );

x *= 2.0f;

}

while ((float)(2.0 + x) != x);

printf( "\nCalculated x: %G\n", x );

return 0;

}Code (Text):Calculated x: 3.68935E+019

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# The smallest floating point x such that x+2=x

Loading...

Similar Threads for smallest floating point |
---|

Need some advice on an appropriate computer language to use |

Testing floating point numbers for equality |

Is there a byte that never occurs in a float? |

IEEE float division |

**Physics Forums | Science Articles, Homework Help, Discussion**