You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 5173 Reporter: warwick Status: closed (set by @xavierleroy on 2010-11-11T17:21:50Z) Resolution: not a bug Priority: normal Severity: feature Version: 3.12.0 Category: ~DO NOT USE (was: OCaml general) Related to:#4170 Monitored by:@Chris00
Bug description
Sorry ... 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.
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)
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 (http://thelema.github.com/batteries-included/hdoc/) 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.
Original bug ID: 5173
Reporter: warwick
Status: closed (set by @xavierleroy on 2010-11-11T17:21:50Z)
Resolution: not a bug
Priority: normal
Severity: feature
Version: 3.12.0
Category: ~DO NOT USE (was: OCaml general)
Related to: #4170
Monitored by: @Chris00
Bug description
Sorry ... 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, ...
The text was updated successfully, but these errors were encountered: