User:Berni44/Floatingpoint

From D Wiki
Revision as of 18:38, 13 February 2021 by Berni44 (talk | contribs)
Jump to: navigation, search

An introduction to floating point numbers

You probably already know, that strange things can happen, when using floating point numbers.

An example:

import std.stdio;

void main()
{
    float a = 1000;
    float b = 1/a;
    float c = 1/b;
    writeln("Is ",a," == ",c,"? ",a==c?"Yes!":"No!");
}

Did you guess the answer?

Is 1000 == 1000? No!

Nano floats

To understand this strange behavior we have to look at the bit representation of the numbers involved.

... to be continued