HP Forums
Rounding errors when mimicking Mod() with FP() - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Rounding errors when mimicking Mod() with FP() (/thread-5867.html)



Rounding errors when mimicking Mod() with FP() - StephanP - 03-13-2016 03:56 PM

In an earlier thread, I've learned that modulo calculations are supported in CAS through the %% operator.
Still not quite familiar within the CAS environment, I tried the following in normal mode.

I've used the following to generate the subgroup H=<10> of G=Z13*
[attachment=3223]

Which gave me the following results:
[attachment=3224]

Starting x=2 on the Emulator and x=5 on the HP Prime, the list shows results with rounding errors.
This does not occur with the TI-84 or the Casio CG-20.


RE: Rounding errors when mimicking Mod() with FP() - Fortin - 03-13-2016 06:34 PM

Entering 10^X MOD 13 should produce what you'd expect. Also, the MOD operator will produce results beyond 12 where the FP becomes 0.


RE: Rounding errors when mimicking Mod() with FP() - StephanP - 03-14-2016 07:30 AM

Ah, I've found it in the Catalog.
Thanks


RE: Rounding errors when mimicking Mod() with FP() - cyrille de brébisson - 03-14-2016 08:14 AM

Hello

Similar rounding errors are inevitable when working with floating point numbers.
Various floating point (FP) systems will behave differently depending on their implementation (binary/decimal, number of internal/external digits used for precision).
Some system will try to hide the "problems" (which itself causes other issues), other will not. Some will hide it by hiding the real value of numbers (which means that subsequent calculations are technically OK, but yield a 'strange' result), some by modifying the numbers...

Fixing a given system for a given case usually breaks it for another case :-)

Here, you want to do exact arithmetics. This can be done using binary integers or the CAS.

use #10d^R->B(X) MOD #13d for example for F1(X) and you get the result that you want (warning, the function is only defined for integer X.). You can go to the num setup, set step to 1 and got to NUM view to see the data.

irem(10^X,13) should also do what you want (this is a CAS function, integer remener).

Cyrille


RE: Rounding errors when mimicking Mod() with FP() - Fortin - 03-14-2016 11:18 AM

(03-14-2016 07:30 AM)StephanP Wrote:  Ah, I've found it in the Catalog.

MOD can also be found in toolbox->math->arithmetic->modulus