Skip to content

Add Pervasives.pi#964

Closed
Chris00 wants to merge 1 commit intoocaml:trunkfrom
Chris00:trunk
Closed

Add Pervasives.pi#964
Chris00 wants to merge 1 commit intoocaml:trunkfrom
Chris00:trunk

Conversation

@Chris00
Copy link
Copy Markdown
Member

@Chris00 Chris00 commented Dec 11, 2016

Fixes #4170

@Chris00
Copy link
Copy Markdown
Member Author

Chris00 commented Dec 11, 2016

See also the discussion for Base.

@nojb
Copy link
Copy Markdown
Contributor

nojb commented Dec 11, 2016

Sorry if I missed this in the linked discussions, but why is the result of, say, 4. *. atan 1. not a reliable way to obtain \pi ?

@Chris00
Copy link
Copy Markdown
Member Author

Chris00 commented Dec 11, 2016

let epsilon_float =
float_of_bits 0x3C_B0_00_00_00_00_00_00L

let pi = 0x3.243f6a8885a308d313198a2e037073
Copy link
Copy Markdown
Member

@gasche gasche Dec 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there more precision in this definition than what OCaml doubles can represent?

# Printf.sprintf "%h" 0x3.243f6a8885a308d313198a2e037073;;
- : string = "0x1.921fb54442d18p+1"

Do 0x3.243f6a8885a308d313198a2e037073 and 0x1.921fb54442d18p+1 represent different floating-point numbers? The latter is also exactly what I get on my machine with 4. *. atan 1. (but maybe atan's precision depends on the system and shouldn't be relied on for a definition?).

@Chris00
Copy link
Copy Markdown
Member Author

Chris00 commented Dec 11, 2016 via email

@mshinwell
Copy link
Copy Markdown
Contributor

Are we happy with the extra item in the global namespace introduced by this patch?

@dbuenzli
Copy link
Copy Markdown
Contributor

Are we happy with the extra item in the global namespace introduced by this patch?

I'd rather have a Float module for this.

@alainfrisch
Copy link
Copy Markdown
Contributor

I'd rather have a Float module for this.

I agree that having one module in the stdlib for each built-in type is a good direction (if only to allow Set.Make(Float)), and that if we had a Float module already, this would be the natural place to put pi.

Adding modules to the stdlib (esp. with very common names) can conflict with existing user modules. Perhaps a good time to study ways to add modules to the stdlib without risking such conflict. One possibility would be to name the new module CamlFloat (or StdlibFloat, etc) and expose an alias module Float = CamlFloat in Pervasives.

@ghost ghost mentioned this pull request Jan 13, 2017
@damiendoligez
Copy link
Copy Markdown
Member

At the developer meeting two days ago, we decided this PR will be suspended until a Float module is added to the stdlib (sometime after #1010 is merged).

@damiendoligez damiendoligez added this to the 4.07-or-later milestone Sep 29, 2017
@alainfrisch
Copy link
Copy Markdown
Contributor

Now that #1010 is merged, I'm "unsuspending" this PR. It is now possible to add a Float submodule in Stdlib without polluting the global namespace.

@alainfrisch
Copy link
Copy Markdown
Contributor

There is now a Float module in the stdlib.

@Chris00 : could you amend this PR to add the new value to that module (only)?

@Chris00
Copy link
Copy Markdown
Member Author

Chris00 commented Mar 21, 2018

Superseded by #1674

@Chris00 Chris00 closed this Mar 21, 2018
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
…l#964)

* using HTML list tags on search results page

* ol instead of ul

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants