caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] string_of_float (0.1 +. 0.2)
@ 2022-06-15  1:59 Kenichi Asai
  2022-06-15  6:22 ` Andreas Rossberg
  2022-06-15 14:07 ` Gabriel Scherer
  0 siblings, 2 replies; 28+ messages in thread
From: Kenichi Asai @ 2022-06-15  1:59 UTC (permalink / raw)
  To: caml-list

On OCaml 4.12.0 on M1 mac, I got:

# 0.1 +. 0.2;;
- : float = 0.300000000000000044
# string_of_float (0.1 +. 0.2);;
- : string = "0.3"

Why don't I obtain "0.300000000000000044" here?

Here is some background.  I am writing an OCaml interpreter that
mimics most part of the original OCaml interpreter.  In the OCaml
interpreter, 0.1 and 0.2 are represented as

Pexp_constant (Pconst_float ("0.1", None))
Pexp_constant (Pconst_float ("0.2", None))

When I add these two numbers, I would have to execute

let a = float_of_string "0.1"
let b = float_of_string "0.2"
let c = a +. b
let d = string_of_float c

and then return

Pexp_constant (Pconst_float (d, None))

At this point, however, since d is "0.3" instead of
"0.300000000000000044" (even though c is 0.300000000000000044), I
cannot return 0.300000000000000044 as a result.  How can I mimic the
OCaml behavior?

Sincerely,

-- 
Kenichi Asai

^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Caml-list] unsubscribe
@ 2022-06-16 12:57 Gustave Nimant
  0 siblings, 0 replies; 28+ messages in thread
From: Gustave Nimant @ 2022-06-16 12:57 UTC (permalink / raw)
  To: caml-list

unsubscribe


^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Caml-list] unsubscribe
@ 2022-06-10 15:15 Gustave Nimant
  0 siblings, 0 replies; 28+ messages in thread
From: Gustave Nimant @ 2022-06-10 15:15 UTC (permalink / raw)
  To: caml-list

unsubscribe


^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Caml-list] unsubscribe
@ 2022-06-09  4:32 daniel Ding
  0 siblings, 0 replies; 28+ messages in thread
From: daniel Ding @ 2022-06-09  4:32 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 12 bytes --]

unsubscribe

[-- Attachment #2: Type: text/html, Size: 133 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Caml-list] unsubscribe
@ 2021-11-01 13:11 Bryan Starbuck
  0 siblings, 0 replies; 28+ messages in thread
From: Bryan Starbuck @ 2021-11-01 13:11 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 11 bytes --]

unsubscribe

[-- Attachment #2: Type: text/html, Size: 440 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Caml-list] unsubscribe
@ 2021-09-17 11:34 jean-denis eiden
  0 siblings, 0 replies; 28+ messages in thread
From: jean-denis eiden @ 2021-09-17 11:34 UTC (permalink / raw)
  To: caml-list

unsubscribe

^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Caml-list] unsubscribe
@ 2021-05-26 13:13 Dan Frumin
  0 siblings, 0 replies; 28+ messages in thread
From: Dan Frumin @ 2021-05-26 13:13 UTC (permalink / raw)
  To: caml-list




^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Caml-list] unsubscribe
@ 2021-04-11 18:31 jean-denis eiden
  0 siblings, 0 replies; 28+ messages in thread
From: jean-denis eiden @ 2021-04-11 18:31 UTC (permalink / raw)
  To: caml-list

unsubscribe

^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Caml-list] unsubscribe
@ 2021-01-04 16:44 Adam Johnson
  2021-01-04 16:57 ` Van Chan Ngo
  0 siblings, 1 reply; 28+ messages in thread
From: Adam Johnson @ 2021-01-04 16:44 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 11 bytes --]

unsubscribe

[-- Attachment #2: Type: text/html, Size: 44 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Caml-list]  unsubscribe
@ 2020-12-18 20:15 Alexei
  0 siblings, 0 replies; 28+ messages in thread
From: Alexei @ 2020-12-18 20:15 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 12 bytes --]

unsubscribe

[-- Attachment #2: Type: text/html, Size: 90 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Caml-list] unsubscribe
@ 2020-12-18 16:11 Hunter
  0 siblings, 0 replies; 28+ messages in thread
From: Hunter @ 2020-12-18 16:11 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 12 bytes --]

unsubscribe

[-- Attachment #2: Type: text/html, Size: 33 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Caml-list] unsubscribe
@ 2020-11-25 18:30 Hunter
  0 siblings, 0 replies; 28+ messages in thread
From: Hunter @ 2020-11-25 18:30 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: Type: text/html, Size: 26 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2022-06-16 12:57 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15  1:59 [Caml-list] string_of_float (0.1 +. 0.2) Kenichi Asai
2022-06-15  6:22 ` Andreas Rossberg
2022-06-15  7:00   ` François Pottier
2022-06-15 14:07 ` Gabriel Scherer
2022-06-15 14:25   ` Daniel Bünzli
2022-06-16  1:45     ` Kenichi Asai
2022-06-16  6:24       ` Oleg
2022-06-16  9:01         ` Andreas Rossberg
2022-06-16  9:14           ` [Caml-list] unsubscribe Jean-Denis EIDEN JEAN-DENIS
  -- strict thread matches above, loose matches on Subject: below --
2022-06-16 12:57 Gustave Nimant
2022-06-10 15:15 Gustave Nimant
2022-06-09  4:32 daniel Ding
2021-11-01 13:11 Bryan Starbuck
2021-09-17 11:34 jean-denis eiden
2021-05-26 13:13 Dan Frumin
2021-04-11 18:31 jean-denis eiden
2021-01-04 16:44 Adam Johnson
2021-01-04 16:57 ` Van Chan Ngo
2021-01-04 17:28   ` Yawar Amin
2021-01-04 18:32     ` Xavier Leroy
2021-01-04 19:42       ` Yawar Amin
2021-01-04 19:51         ` Daniil Baturin
2021-01-04 20:04           ` Yawar Amin
2021-01-04 21:07         ` Philippe Wang
2021-01-04 21:26           ` Yawar Amin
2020-12-18 20:15 Alexei
2020-12-18 16:11 Hunter
2020-11-25 18:30 Hunter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).