INT cannot be coerced to LONG REAL in a strong-UNIT
Jose E. Marchesi
jemarch@gnu.org
Fri Jun 20 22:01:45 GMT 2025
> Hello Chris.
>
>> Good day,
>>
>> I'm running into what seems to be an error to me, based on my still-rusty
>> Algol 68 coercion fu.
>>
>> I have this expression:
>>
>> long real a0 = ABS "0";
>>
>> and ga68 gives me this error:
>>
>> error: INT cannot be coerced to LONG REAL in a strong-UNIT
>>
>> That doesn't seem correct to me; as far as I know, INT can be widened to
>> REAL and REAL to LONG REAL in a strong context.
>>
>> I must be missing something but not sure what...
>
> The widening of real to long real is a Genie extension and not standard
> Algol 68. There is no widening coercion from reals to reals, nor from
> ints to ints. Only from int to real of the same size, from real to
> complex of the same size, from bits to row of booleans and from bytes to
> row of chars.
>
> The _of the same size_ restriction is expressed in the grammar via
> consistent substitution, like in 6.5.1.a:
>
> a) widened to{b,61A} SIZETY real FORM :
> MEEK{61C} SIZETY integral FORM.
>
> This seems to be a common misconception. Recently I had to correct the
> Wikipedia article on this regard.
>
> You need to use the leng operator to go from real to long real.
By the way, you can find the entire grammar, including the GNU
extensions implemented by GCC, in the file gcc/gcc/algol68/ga68.vw in
the source tree.
If you use Emacs you can use the mode at
https://git.sr.ht/~jemarch/vw-mode to get syntax highlighting and
automatic indentation.
More information about the Algol68
mailing list