[RFC] We need an ENTIER that does ceil, CENTIER?
Remington Furman
remington@remcycles.net
Sat May 16 14:26:50 GMT 2026
On 5/16/26 3:08 AM, Jose E. Marchesi wrote:
> Hello Paul.
>> On 16/05/2026 03:11,algol68-request@gcc.gnu.org wrote:
>>> Date: Fri, 15 May 2026 23:07:42 +0200
>>> From: "Jose E. Marchesi"<jemarch@gnu.org>
>>> To:algol68@gcc.gnu.org
>>> Subject: Re: [RFC] We need an ENTIER that does ceil, CENTIER?
>>> Message-ID:<871pfc5qld.fsf@gnu.org>
>>> Content-Type: text/plain
>>>
>>>
>>> Sooo, I found this in the PDP-11 ALGOL 68S manual:
>>>
>>> ----
>>> # Two flavors of real-to-integer conversion #
>>>
>>> round 1.6 yields 2 proc (real) int
>>> entier 1.6 yields 1 proc (real) int
>>> round -1.4 yields -1
>>> entier -1.4 yields -2
>>> ----
>>>
>>> They use ROUND for ceil.
I don't think that's clear from the limited example output. For
example, perhaps round(1.4) is 1, not 2, and round(-1.6) is -2. At
least, that's what I would expect from a round() function.
>>> I suggest we do the same, as there is at least some established
>>> tradition about it..
>> I suggest not. CEIL (or CEILING as second-best) unambiguously
>> indicates rounding up. ROUND, to me at least, could mean round up,
>> round down or round to nearest.
And when rounding to nearest, you have to decide how to handle 0.5 and
-0.5: round them up, down, away from zero, towards zero, or to the
nearest even number.
https://en.wikipedia.org/wiki/Rounding#Rounding_to_the_nearest_integer
In a digital signal processing context, rounding to the nearest even
number is useful, because you don't want to change the mean value of a
signal when rounding. In DSP jargon that's called "adding a DC bias".
Halfway values might seem like an uncommon occurrence with wide floating
point data types, but happen often in fixed-point integer DSP
implementations.
https://zipcpu.com/dsp/2017/07/22/rounding.html
Or any context when there are few significant digits to work with:
https://chem.academy/notes/bankers-rounding.html
>> Mathematical usage in English is invariably floor and ceiling, likely
>> because of the ambiguity concern. Given that ENTIER is already built
>> in to the language and yet is not used in any other language AFAIK, I
>> see relatively little attraction in the established tradition
>> argument.
> Thank you for the feedback.
>
> Nelson Beebe has also urged me to not use ROUND at all and to stick to
> CEIL and FLOOR instead.
I think that's a good call. CEIL and FLOOR are simple and unambiguous,
but rounding is a more complicated subject than grade school math
suggests. So one ROUND function isn't suitable for all cases.
For reference, the C99 standard library added a family of functions so
you can choose the behavior you want:
https://cppreference.com/c/header/math#Nearest_integer_floating-point_operations
Some of them depend on the current FPU mode, and C99 also lets you
change it:
https://cppreference.com/c/numeric/fenv
Wikipedia says "[round half to even] is the default rounding mode used
in IEEE 754 <https://en.wikipedia.org/wiki/IEEE_754> operations for
results in binary floating-point formats."
-Remington
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/algol68/attachments/20260516/4d3e4102/attachment-0001.htm>
More information about the Algol68
mailing list