# Rational Numbers

BlitzMax Modules Forums/Brucey's Modules/Rational Numbers
| ||

Announcing yet another addition to the modules related to mathematics : BaH.RationalRational numbers are any number that can be expressed as the ratio or quotient a/b, of two integers. Fractions! This module is built on the Boost library, so you will also need BaH.Boost. (Other modules already using BaH.Boost, include BaH.Mathtoolkit and BaH.DateTime),Here's a small example of use : 1/3 * 1/6 = 1/18 Local third:TRational = Rational(1, 3) ' 1/3 Local sixth:TRational = Rational(1, 6) ' 1/6 Local eighteenth:TRational = third.MultiplyR(sixth) ' multiply by rational The download is available from the google code site, here.Have fun :-) |

| ||

can be expressed as the quotient a/b of two integers I would call it the ratio of two integers, just to drive home the point. |

| ||

Very true. Thanks. |

| ||

Interesting ! I wonder in what situation this module would be useful. |

| ||

Didn't that already exists as one of your modules? Or do I have a deja-vu? Or did I write such an module a long time ago? Strange ;-) Usage Example: Writing an scientific calculator. This is just another situation which screams for operator overloading. ;-) Wouldn't it be cool to just say: Local a:TRational, b:TRational, c:TRational a = Rational(1, 3) b = Rational(2, 5) c = a * b But this is just a wish… unlikely that Mark does something like that. |

| ||

Wouldn't it be cool to just say: Yes, it would... which is how it works in C++, and as such in the wrapper : boost::rational<int> * bmx_rational_multiplyr(boost::rational<int> * rat, boost::rational<int> * value) { boost::rational<int> * r = new boost::rational<int>(); *r = *rat * *value; return r; } Unfortunately, we have to live with what BlitzMax allows us to do... Didn't that already exists as one of your modules? It's been in SVN for a while, but unreleased. |

| ||

yes please more maths brucey! |

| ||

yes please more maths brucey! I imagine this stuff would be up your alley... which is implemented in BaH.MathToolkit. I'm always on the lookout for other interesting (non-GPL) libraries... :-) |