Thinking about widening
Jose E. Marchesi
jemarch@gnu.org
Sun Jan 18 07:55:46 GMT 2026
> Is widening worthwhile?
>
> I am assuming I can coerce int to real with real(42) etc.
Without widening, you can't.
Casts in Algol 68 are real casts, unlike the degenerated version of the
concept found in C and all others: they just provide shape in the form
of a syntactic context and goal mode. They still rely on the coercions
to do the work. So you would need an operator or procedure instead.
> The value in doing that - well there is this assumption that converting int
> to real is cool and needs no special ceremony, but going from real to int,
> well! We must decide whether to round or truncate and if truncating whether
> toward zero or -infinity.
I suppose that is the reason why the coercion goes the int -> real ->
compl direction :)
> I'm not sure I buy the argument that int to real is foolproof so let's just
> do it.
>
> For one thing it assumes that the programmer knows s/he is doing it. Uh
> huh. Always aware of what's going on in our code we programmers.
>
> For another it leads to the need to have integer division of integers vs.
> floating point division of widened integers. Well if we need to be aware of
> when we want an integer result (by the way how is negative integer division
> handled again?) how much effort is it to more generally recognize that
> there is the need for a coercion?
Note that widening also includes BITS -> []BOOL and BYTES ->[]CHAR.
> </end-of-saturday-night-rant>
>
> Chris Hermansen · clhermansen "at" gmail "dot" com
>
> C'est ma façon de parler.
More information about the Algol68
mailing list