Conversation

today in "cross-language RPC": Rust and Swift have a different bit pattern for pi

1
2
1

@ju Ya

0x40490FDB Rust
0x40490FDA Swift
(The f64 constants are the same)

3
0
0

@fasterthanlime amazing.

But now I want to know why you need PI to be equal on the bit level 😆

1
0
0

@ju I don't, but some integration tests used the PI constant on both sides and.. understandably failed.

0
0
0

@fasterthanlime @ju I never want to underestimate the possibility for weird corner cases in IEEE floats, but surely different bit patterns mean different values, as long as a NaN isn't involved? According to pari/gp, rust's value is closer: it's 8.7e-8 too big, while swift's is 1.5e-7 too small.

0
0
0

@fasterthanlime @ju interesting

rust one is 3.1415927
swift one is 3.1415925
pi starts with 3.14159265…

seems that swift is rounding it in the wrong direction?

1
0
1

@fasterthanlime @ju hypothesis: this is because of the rounding mode used during parsing

rust uses standard round to zero, ties to even. the f64 representation has a 1 bit after the 23 mantissa bits that also exist on f32. closest even number is 4.0 so it rounds up

i guess swift uses round to zero or round to -Inf rounding mode for number parsing?

0
0
2