Regarding literals and loop indices modes / programming friction

jpl jpl.algol68@gmail.com
Mon Jan 26 06:52:47 GMT 2026


My experimentation is showing that indeed long_cos (and friends) is
needed for long arguments.  Also a "long_pi" is needed for use with
long reals:

begin
   real x:=10, y:=20, z;
   long real xx:=Leng 10, yy:= Leng 20, zz;

   z := cos(z);
   zz := cos(zz)

Yields errors:
message.a68:11:10: error: ‘ref long real’ cannot be coerced to ‘real’
in a strong-argument
   11 |    zz := cos(zz)
         |          ^
message.a68:11:4: error: ‘real’ cannot be coerced to ‘long real’ in a
strong-unit
   11 |    zz := cos(zz)
      |    ^



This Works just fine:

   z := cos(z);
   zz := long_cos(zz);

Without using long_pi we get error:

   z := cos(pi*z);
   zz := long_cos(pi*zz)

message.a68:23:21: error: dyadic operator real ‘*’ ref long real has
not been declared
   23 |    zz := long_cos(pi*zz)
         |                     ^

end


Thanks for looking at this.  And it is a tremendous relief that (if I
understand correctly), that "cos(pi*x) "should just work whether x is
real or long x.

On Sun, Jan 25, 2026 at 11:00 PM Jose E. Marchesi <jemarch@gnu.org> wrote:
>
>
> > Regarding the SIN monadic op mentioned by Mohammad-Reza:
> >
> > On Sun, Jan 25, 2026 at 4:07 PM Mohammad-Reza Nabipoor
> > <mnabipoor@gnu.org> wrote:
> >>
> >> Another way is to define SIN/COS as monadic operators, and then enjoying the overloading
> >> capabilities:
> >>
> >> ```algol68
> >>  op SIN = (real r) real: sin (r),
> >>      SIN = (long real lr) long real: long_sin (lr),
> >>      COS = (real r) real: cos (r),
> >>      COS = (long real lr) long real: long_cos (lr);
> >> ```
> >
> > Is there any reason why this would not be done for all such
> > (reasonable) mathematical functions (at the language level)?
> >
> > I mean, could not our present day "sin" be renamed to "sin_real", and
> > then create a monadic operator named "sin" which would allow all
> > variants of real modes?  It appears it would provide broad benefits to
> > the user.
>
> Standard `sin' and `cos' operators are just regular operators, and they
> are provided for the following modes:
>
>   real -> real
>   long real -> long real
>
> So I don't really understand why you would need to define any of the
> operators above, nor the need for long_sin or long_cos.
>
> Well, other than it looks like I forgot to implement `long real'
> versions of `arccos', `arcsin', `arctan', `cos', `exp', `ln', `sin',
> `sqrt', and `tan' ^^
>
> Will do it this week.  These standard routines (and pi, sqrt, exp, ln)
> are always supposed to be available for all supported sizes of real.
>
> Remember that widening is not active in firm contexts, so `int' and
> `real' are not firmly related and you can define separated overloaded
> operators for these.
>
> >
> > Probably a silly question. But I am curious.
>
>


More information about the Algol68 mailing list