[fpc-devel] -1 mod 3

Dmitry Lizorkin lizorkin at ispras.ru
Wed Nov 5 13:18:11 CET 2008


Hello!

>> There is no need for such a switch. No programs needs it, because if
>> you need to positive value you need just one if statement.
> Or the beautiful iso-compliant Abs? <smile>

That's not that simple. In particular, ISO-compliant result for (-1) mod 3 
is 2, not abs(-1). As the result, one cannot express the requested behaviour 
within a single expression and has to use either several statements or 
implement a user-defined function equivalent to ISO-compliant "mod".

> So the "mod" in Delphi/FPC is just called wrong. ;)

>From this perspective, you could as well remove "mod" from the language at 
all. With this design decision taken, every user could at least have the 
ability to re-implement the "mod" functionality using "div" and either 
ISO-compliant or Delphi-specific manner. This is anyway better than spending 
0.5+ hours searching for a bug in a written program and discovering that it 
is the standard mathametical operation that behaves unexpectedly.

> I agree, no real life need.

Except probably for my 150 students to whom i can no longer recommend FPC as 
a reference implementation.

Dmitry




More information about the fpc-devel mailing list