Skip to content

Instantly share code, notes, and snippets.

@svetlanama
Last active December 7, 2016 11:06
Show Gist options
  • Save svetlanama/f4abf2528c0026b5e4732bc7e8a45f0b to your computer and use it in GitHub Desktop.
Save svetlanama/f4abf2528c0026b5e4732bc7e8a45f0b to your computer and use it in GitHub Desktop.
Float Point Values Computation
import UIKit
let a = 1e+30
let b = -1e+30
let c = 1.0
let sum1 = (a + b) + c
let sum2 = a + (b + c)
//Representation of floating point value according to IEEE 754
let lbits = Double(-0.06)
lbits.sign //sign
lbits.exponent //exponent
lbits.significand //mantissa
@svetlanama
Copy link
Author

We all know the Math rule by permutation sum is not changed so
(a + b) + c = a + (b + c), and it seems to be that it is not TRUE in programming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment