[fpc-devel] -1 mod 3
Vinzent Höfler
JeLlyFish.software at gmx.net
Wed Nov 5 18:48:19 CET 2008
Schatzl Thomas wrote:
> Hello,
>
>> Datum: Wed, 05 Nov 2008 18:04:01 +0100
>> Von: "Vinzent Höfler" <JeLlyFish.software at gmx.net>
>>> Unless they make use of Ada.
>> Which just has both, that's all. ;)
>>
>> As an alternative one could read some other language reference manuals
>> and notice that - surprisingly - at least two of the more common "real
>> world languages" don't even have a "modulo" operation:
>>
>> ISO/IEC9899:1999: (C99)
>
> [...]
>
>> Java:
>
> [...]
>
>> So, IMO somebody at Borland got it wrong, just because someone at Intel
>> did it that way - and this has definitely and absolutely nothing to do
>> with a "computer science implementation".
>>
>>
>> SCNR,
>
> Just because it's called "remainder" in other languages (and if you had
> actually read the specs ;), the result in these languages is still
> the same as for the FPC "mod" operator.
Yes, that's precisely what I said: They do NOT incorrectly call it
"mod(ulo|us)" (aside the fact, that they use unreadable special chars
for the operator), they call it "remainder".
It appears, you didn't read my mail, not that I didn't read the specs,
like you seem to suggest. :P
> E.g. both read, having the exact same wording in both specs,
> "...produces a result value such that (a/b)*b+(a%b) is equal to a."
>
> I.e. for a=-1 and b=3 the result is -1 following from a%b = a - (a/b)*b for both C99 and Java.
Yes, absolutely. That's what they define it does, and that's exactly
what someone should expect from a "rem" operation. Those languages
simply don't have a "mod" operator (I hate to repeat myself, but it
seems necessary).
But: If "mod" is a defined operator, it usually behaves differently:
-- 8< --
$ cat modulo.adb
with Ada.Text_IO; use Ada.Text_IO;
procedure modulo is
begin
Put_Line (Integer'Image ((-1) mod 3));
Put_Line (Integer'Image ((-1) rem 3));
end modulo;
jlfencey at charlie ~
$ gnatmake.exe modulo.adb
gcc -c modulo.adb
gnatbind -x modulo.ali
gnatlink modulo.ali
jlfencey at charlie ~
$ ./modulo.exe
2
-1
-- 8< --
And the fact still remains, that Delphi (and thus FPC) call the
"remainder" operation a "modulus" operation. That's - well,
counterintuitive.
Vinzent.
More information about the fpc-devel
mailing list