Jump to content
  • Advertisement
Sign in to follow this  
Antheus

Accurate math library

This topic is 3748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know of a perfectly accurate math library? Something that would be capable of the following:
a = 1/3;
b = a * Pi;
c = b / Pi;

c == a; // true
Obviously, it would need internal and external representation, where evaluating a would result in 0.3333333, and b = 1.047198, but would preserve adequate information internally to be able to retain precision loss for as long as needed. Needless to say, internal storage would likely need to contain full expression. Just curious, don't have any pressing need for this.

Share this post


Link to post
Share on other sites
Advertisement
Haskell's lazy evaluation could do it, but that's probably not what you're looking for.

Using GHCi:
Prelude> let a = 1 / 3
Prelude> let b = a * pi
Prelude> let c = b / pi
Prelude> c == a
True

Share this post


Link to post
Share on other sites
What you're probably after is a Computer Algebra System. There's a few different ones linked from Wikipedia: http://en.wikipedia.org/wiki/Computer_algebra_system

Share this post


Link to post
Share on other sites
Representing irrationals like pi exactly is not possible, so no. Libraries and languages that support arbitrary precision arithmetic will let you do similar things with ratios, though.

For instance, in lisp:


(let ((n (/ 17 (expt 13 99))))
(print n)
(print (* n (expt 13 99))))

17/190718085458920964116236375748835779710674959067303165370168392262012207679844273858329666379998629245551661077
17




This does not work for floats.

[Edited by - gsg on February 20, 2008 8:14:52 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by gsg
Representing irrationals like pi exactly is not possible, so no.


Yes it is. You just did it – 'pi'. A symbolic maths system would deal fine with this. It would, of course, need to be converted to some alternative representation to be used outside of the system (either some finite-precision form, or some graphical or string representation of the symbolic form) but it would certainly allow examples like the original to work correctly. In fact, this is almost exactly what the OP specifies.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!