Are there mainstream languages whose floating points are not implemented with IEEE 754, so 0.1 + 0.2 actually does equal 0.3? Because it seems uninformed to make fun of JavaScript for that if other languages follow the floating point standard with the same limitations.
Conversation
Notices
-
Embed this notice
Josh Justice (codingitwrong@tdd.social)'s status on Thursday, 24-Apr-2025 03:18:17 JST Josh Justice
- Alfred M. Szmidt repeated this.
-
Embed this notice
Daniel Kochmański (jackdaniel@functional.cafe)'s status on Thursday, 24-Apr-2025 03:18:09 JST Daniel Kochmański
@CodingItWrong float is just a wrong type to do that. You may ude language with rational numbers (like common #lisp), or use ratios provided by gmp.
1/10 + 2/10 = 3/10
-
Embed this notice
Jonathan Yu (jawnsy@mastodon.social)'s status on Thursday, 24-Apr-2025 03:18:36 JST Jonathan Yu
@CodingItWrong Maybe if they use arbitrary precision math for everything but that seems like it would be very slow
-
Embed this notice
Alfred M. Szmidt (amszmidt@mastodon.social)'s status on Thursday, 24-Apr-2025 03:18:36 JST Alfred M. Szmidt
@jawnsy It isn't slow, this happens in Lisp. @CodingItWrong
-
Embed this notice
Alfred M. Szmidt (amszmidt@mastodon.social)'s status on Thursday, 24-Apr-2025 03:20:16 JST Alfred M. Szmidt
@CodingItWrong
* (let ((zero-dot-three (+ 0.1 0.2))) (and (eq zero-dot-three 0.3) (= zero-dot-three 0.3)))
T