torsdag 10 juli 2014

Floating point numbers ...

Floating point numbers have some unexpected properties.

Try this in your favourite language (if it has real floats)

Python:
>>> print 0.1 + 0.2 == 0.3
False
 C:
#include <stdio.h>
int main() {  printf("%s\n", 0.1 + 0.2 == 0.3 ? "True" : "False");

$ gcc float.c -o float && ./float 
False 



Inga kommentarer:

Skicka en kommentar