|
From: | Charles Karney |
Subject: | [Octave-bug-tracker] [bug #45587] rem(-0, 1) returns 0 instead of -0 |
Date: | Tue, 21 Jul 2015 18:36:28 +0000 |
User-agent: | Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0 |
Follow-up Comment #9, bug #45587 (project octave): A key point about the C/C++ function fmod (and the related remainder function) is that it is exact (even with floating-point numbers). In lots of applications this is important. It is unfortunate the Octave (and MATLAB) resort to cosmetic "fixes" to ensure that rem(0.94, 0.01) returns 0. Let's see how to do the rem operation exactly a=0.94; b=0.01; a and b are now the closest floating point numbers to 0.94 and 0.01. Now compute ((((a-64*b)-16*b)-8*b)-4*b)-b Each of the multiplication and subtraction operations here is exact and this yields 0.00999999999999993 and this is less that b ans < b -> 1 _______________________________________________________ Reply to this item at: <http://savannah.gnu.org/bugs/?45587> _______________________________________________ Message sent via/by Savannah http://savannah.gnu.org/
[Prev in Thread] | Current Thread | [Next in Thread] |