Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005173OCaml~DO NOT USE (was: OCaml general)public2010-11-04 02:012017-01-03 01:07
Assigned To 
StatusclosedResolutionno change required 
PlatformOSOS Version
Product Version3.12.0 
Target VersionFixed in Version 
Summary0005173: Value of Pi and Math module
DescriptionSorry ... I guess this has been discussed already, but I think the inclusion of a value for Pi would make OCaml easier to learn and use (rather than having to put: let pi = 4. *. atan 1. in your code).

It'd be a problem adding pi to the namespace in Pervasives, so it'd be good to have a Math module. This would give the opportunity to move floating point functions from Pervasives to Math, over time; and also the chance to add some new maths functions or values if required - without cluttering Pervasives.

For example:

Math.round, Math.deg, Math.rad, Math.e, Math.asinh, Math.acosh, Math.atanh, ...
TagsNo tags attached.
Attached Files

- Relationships
related to 0004170resolvedgarrigue pi constant 

-  Notes
warwick (reporter)
2010-11-04 03:59

I just looked at the value of pi more closely (using toplevel OCaml 3.12.0 on Mac) and I didn't realise that the floating point loses some precision, so if you put either of
let pi = 4. *. atan 1.
let pi = 3.1415926535897932384626433832795

You end up with
val pi : float = 3.14159265358979312

(ie ending with ...312 rather than ...323 or ...324 rounded)
xleroy (administrator)
2010-11-11 18:21


You're right that, in retrospect, it would have been preferable to have a separate module for float operations in the standard library. Experience shows, however, that adding a new module in the stdlib with a nice, popular name like Math always introduces incompatibilies in existing Caml code, something that we cannot afford at this point.

Note, however, that OCaml Batteries ( [^]) has a "BatFloat" module very much like what you propose, and it defines "BatFloat.pi" among other useful things. If you have ideas and code for additional floating-point stuff, I'm sure the Batteries people would be receptive.

Concerning the loss of precision: the float you get out of "4 *. atan 1.0" is, indeed, the 64-bit IEEE float closest to the true value of pi. That's the best one can do within the limitations of this float format.

- Issue History
Date Modified Username Field Change
2010-11-04 02:01 warwick New Issue
2010-11-04 03:59 warwick Note Added: 0005699
2010-11-11 18:21 xleroy Note Added: 0005704
2010-11-11 18:21 xleroy Status new => closed
2010-11-11 18:21 xleroy Resolution open => no change required
2013-09-03 17:27 doligez Relationship added related to 0004170
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker