basvandijk / scientific

Arbitrary-precision floating-point numbers represented using scientific notation
BSD 3-Clause "New" or "Revised" License
73 stars 40 forks source link

Division bug? #56

Closed jefdaj closed 6 years ago

jefdaj commented 6 years ago

This hangs with 100% CPU on my machine:

(read "1.0" :: Scientific) / (read "6.0" :: Scientific)

Have I stumbled on a bug in division, or parsing, or am I doing something wrong? It only happens with certain numbers. For example "4.0" instead of "6.0" works.

jefdaj commented 6 years ago

Never mind, this is what fromRationalRepetend is for right?

basvandijk commented 6 years ago

1/6 is a repeating decimal: 0.1(6). Since a Scientific stores the actual decimal digits representing an infinite number of them takes infinite time and space.

Indeed use fromRationalRepetend. Do note that this function consumes space linear in the number of digits in the resulting scientific. For 0.1(6) that's not a problem though since the repetition starts very early.

Can you tell a bit more about your use-case?