orc-lang / orc

Orc programming language implementation
https://orc.csres.utexas.edu/
BSD 3-Clause "New" or "Revised" License
42 stars 3 forks source link

fix messy numeric tower #18

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Our numeric tower is a mess. We default to BigInteger and BigDecimal, but
BigDecimal is not capable of representing many rational numbers so we
implicitly convert to double when necessary.

First, we should get rid of BigDecimal since the cases when it is
appropriate (monetary transactions) are too rare to warrant making it the
default. This means that integral operations default to BigInteger, and
floating-point operations default to double.

Second, we should think about adding a precise rational type ala Scheme.

Finally, we need to ensure we have consistent and reasonable conversions
when operations mix types. Again, Scheme's numeric tower can provide
guidance about when it's appropriate to switch from exact to inexact
representations.

Original issue reported on code.google.com by adrianqu...@gmail.com on 18 Apr 2009 at 3:02

GoogleCodeExporter commented 9 years ago
We should consider following Python's example
http://www.python.org/dev/peps/pep-0238/ and making "/" perform rational or 
inexact
division for integers rather than the less common integral (rounding) division. 
We
can provide the library "div" function (like Haskell) for integral division.

Original comment by adrianqu...@gmail.com on 30 Apr 2009 at 11:17

arthurp commented 7 years ago

This will be easier after handling #173 (operator methods).

arthurp commented 7 years ago

We may be getting to a time where performing this fix is worth it. The reason is that the PorcE backend can actually do native unboxed double math and even use Long for "small" numbers and switch silently to BitInt when we are forced to. Using Long for small numbers could actually gain a bit of performance in lots of common cases like counting things.