cheddar-lang / Cheddar

🧀 Cheddar, the language that works for you
cheddar.vihan.org
Apache License 2.0
28 stars 9 forks source link

Rational Limitations #91

Open ghost opened 8 years ago

ghost commented 8 years ago

Version: 1.0.0

Problem

Rationals don't support very big/very small numbers and sometimes produce incorrect result

Desired Behavior

Work correctly ._.

How to Reproduce

  1. Do Rational.of(0.00005)
  2. It print 0 / 1
  3. Do Rational.of(1000000000000)
  4. It print -727379968 / 1 (Probably integer size issue, but ._.)
LegionMammal978 commented 8 years ago
Rational.of(0.00005)

Rational.of (and indeed, all implicit conversion to Rational) from a decimal has a maximum denominator of 1000 due to floating-point precision issues. I'll see if I can do anything about these cases.

Rational.of(1000000000000)

See:

> 1000000000000|0
-727379968

Numerators and denominators in Rational can only be exact numbers.

vihanb commented 7 years ago

@LegionMammal978 btw, could you add support for a cheddar constructor/casting. so Rational { 0.5 }, Rational { 1, 2 }, Rational::0.5 can all work?