|Anonymous | Login | Signup for a new account||2015-03-04 21:24 CET|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0005173||OCaml||OCaml general||public||2010-11-04 02:01||2013-09-03 17:27|
|Status||closed||Resolution||no change required|
|Target Version||Fixed in Version|
|Summary||0005173: Value of Pi and Math module|
|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.
Math.round, Math.deg, Math.rad, Math.e, Math.asinh, Math.acosh, Math.atanh, ...
|Tags||No tags attached.|
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.
|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|
|Copyright © 2000 - 2011 MantisBT Group|