-> Q err [NOT A BUG]

Bugs in ND1 (report'em, get'em fixed)

-> Q err [NOT A BUG]

Postby neo1111 » Mon Oct 21, 2013 6:03 am

The -> q function either has a bug or not enough precision .

Example 5/7 + 9/11
Gives 1 1 133116883/250000000 fraction

Should be 1 1 41/77 fraction

If you convert both to fractions first and add you get correct ans.

If you convert to dec you get

1 1.53246753246753

Then ->q gives what's above.
Posts: 1
Joined: Sun Oct 23, 2011 12:15 pm

Re: -> Q err

Postby oliver » Mon Oct 21, 2013 9:45 pm

->Q is pretty cheaply implemented and it's easy to have it produce sub-optimal results. I wouldn't call this an error per se. In the example you give the sub-optimal result is still accurate to 9 digits. (In comparison to a 50g, this implementation will sometimes be worse, sometimes be better, depending on the concrete input.)

If you need a higher quality result, there's a way: try ->CF, eval
->CF converts into a continuous fraction, which is way more expensive and gives a way better result. Non-truncated CFs convert to a fraction when you evaluate them. (Truncated CFs, indicated with a "..." extension, convert to a BigFloat, where the precision you set via setBigFPrecision determines how many digits the result will have.)

Tried on your decimal ->CF eval will actually return the expected fraction.

Hope that helps.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest