Inefficiency of `mod'
Adriaan van Os
gpc at microbizz.nl
Fri Oct 22 13:57:57 CEST 2010
Frank Heckenbach wrote:
> CBFalconer wrote:
>
>> Adriaan van Os wrote:
>>> I might be interesting to note that not all Pascal compilers
>>> follow the ISO 7185 Pascal standard for the mod operator. The
>>> standard states:
>> [...]
>>
>> This is the result of Borland ignoring the standard. There is no
>> excuse, because the standard was available long before the first
>> Turbo Pascal. The drafts were published in Pascal News in the mid
>> '70s. It is one of the reasons many will not consider
>> Delphi/Borland/Turbo to be Pascal.
>
> That's another reason why GPC's `mod' implementation is so hairy
> (because it emulates Borland's in `--borland-pascal') ...
It looks like there is still a problem in the compiler for constant expressions using the mod operator.
program modulo( Output);
var
i, j, m : integer;
begin
i := -10;
j := 100;
m := i mod j;
Writeln( ' m = ', i: 3, ' mod ', j: 3, ' = ', m: 3);
Writeln( '-10 mod 100 = ', -10 mod 100 :3);
end.
[P18:~] adriaan% gp --standard-pascal modulo.pas
[P18:~] adriaan% ./modulo
m = -10 mod 100 = 90
-10 mod 100 = -10
[P18:~] adriaan% gpc -v
Reading specs from /Developer/Pascal/gpc346u4/lib/gcc/i386-apple-darwin9/3.4.6/specs
Configured with: ../gcc-3.4.6/configure --enable-languages=pascal,c --enable-threads=posix
--disable-nls --target=i386-apple-darwin9 --host=i386-apple-darwin9 --build=i386-apple-darwin9
--prefix=/Developer/Pascal/gpc346u4 --with-arch=pentium-m --with-tune=prescott
Thread model: posix
gpc version 20070904, based on gcc-3.4.6
Regards,
Adriaan van Os
More information about the Gpc
mailing list