]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
algol68: Add FLOOR as synonym for ENTIER
authorPietro Monteiro <pietro@sociotechnical.xyz>
Wed, 20 May 2026 23:33:35 +0000 (19:33 -0400)
committerPietro Monteiro <pietro@sociotechnical.xyz>
Wed, 20 May 2026 23:33:35 +0000 (19:33 -0400)
The Revised Report{10.2.3.4.r} specifies ENTIER as the monadic
operator that yields the greatest integral value less than or equal to
a real value (i.e., rounds toward negative infinity).

Many programming languages call this operator FLOOR.  Add FLOOR as a
synonym for ENTIER to allow use of the familiar name; no semantic
change is introduced.

gcc/algol68/ChangeLog:

* a68-parser-prelude.cc (gnu_prelude): Map FLOOR(L real):L int
to ENTIER(L real):L int.
* ga68.texi: Add a section for real operators in the Extended
prelude chapter and document FLOOR.

gcc/testsuite/ChangeLog:

* algol68/execute/entier-1.a68: Add test for FLOOR = ENTIER.
* algol68/compile/floor-1.a68: New test.

gcc/algol68/a68-parser-prelude.cc
gcc/algol68/ga68.texi
gcc/testsuite/algol68/compile/floor-1.a68 [new file with mode: 0644]
gcc/testsuite/algol68/execute/entier-1.a68

index 67edf55f9f7ba0594f4fc87b1494d29ac6934e17..953fba3556bbbc8b6c60a715abce483385f71a5d 100644 (file)
@@ -1378,6 +1378,15 @@ gnu_prelude (void)
   a68_op (A68_EXT, "CLEAR", m, a68_lower_clear3);
   m = a68_proc (M_BOOL, M_LONG_LONG_BITS, M_INT, NO_MOID);
   a68_op (A68_EXT, "TEST", m, a68_lower_test3);
+  /* REAL operators.  */
+  m = a68_proc (M_INT, M_REAL, NO_MOID);
+  a68_op (A68_EXT, "FLOOR", m, a68_lower_entier2);
+  /* LONG REAL operators.  */
+  m = a68_proc (M_LONG_INT, M_LONG_REAL, NO_MOID);
+  a68_op (A68_EXT, "FLOOR", m, a68_lower_entier2);
+  /* LONG REAL operators.  */
+  m = a68_proc (M_LONG_LONG_INT, M_LONG_LONG_REAL, NO_MOID);
+  a68_op (A68_EXT, "FLOOR", m, a68_lower_entier2);
 }
 
 /* POSIX prelude.  */
index da19ddbb329a4ce58854e8c1c72626bdec1a2ec2..ce1e984ad781cb4ad0f0ac3004ce46069caa51af 100644 (file)
@@ -2631,9 +2631,12 @@ to @code{b}.
 Monadic operator that yields the nearest integer to its operand.
 @end deftypefn
 
-@deftypefn Operator {} {@B{entier}} {= (@B{l} @B{real} a) @B{int}}
+@deftypefn Operator {} {@B{entier}} {= (@B{l} @B{real} a) @B{l} @B{int}}
 Monadic operator that yields the integer equal to @code{a}, or the
 next integer below (more negative than) @code{a}.
+
+Selecting the @option{gnu68} dialect provides the @B{floor}
+operator as a synonym for @B{entier}.  @xref{Extended real operators}.
 @end deftypefn
 
 @deftypefn Operator {} {@B{shorten}} {= (@B{long} @B{real} a) @B{real}}
@@ -2970,6 +2973,7 @@ which is the default.
 * Extended rows operators::            Rows and associated operations.
 * Extended boolean operators::         Operations on boolean operands.
 * Extended bits operators::            Bits and associated operations.
+* Extended real operators::            Operations on real operands.
 * Extended math procedures::           Mathematical constants and functions.
 @end menu
 
@@ -3073,6 +3077,16 @@ is not in the range @code{0,L_bits_width)} then the operator yields
 @B{false}.
 @end deftypefn
 
+@node Extended real operators
+@section Extended real operators
+
+@deftypefn Operator {} {@B{floor}} {= (@B{l} @B{real} a) @B{l} @B{int}}
+Monadic operator that yields the integer equal to @code{a} rounded
+towards negative infinity.
+
+An alias for operator @B{entier}.  @xref{Real operators}.
+@end deftypefn
+
 @node Extended math procedures
 @section Extended math procedures
 
diff --git a/gcc/testsuite/algol68/compile/floor-1.a68 b/gcc/testsuite/algol68/compile/floor-1.a68
new file mode 100644 (file)
index 0000000..ae1a233
--- /dev/null
@@ -0,0 +1,4 @@
+# { dg-options "-fstropping=upper -std=algol68" } #
+BEGIN # FLOOR is a GNU extension #
+      FLOOR 1.2 # { dg-error "indicant FLOOR has not been declared properly" } #
+END
index d7c84e23d3e691402b6cae54d8fb46e1af902061..a7ca3803e5adc9ef2bc4659dc9a5002f63baa08e 100644 (file)
@@ -4,5 +4,8 @@ BEGIN REAL x = 3.14, y = 3.80;
       LONG LONG REAL xxx = LONG LONG 3.14, yyy = LONG LONG 3.80;
       ASSERT (ENTIER x = 3 AND ENTIER y = 3);
       ASSERT (ENTIER xx = LONG 3 AND ENTIER yy = LONG 3);
-      ASSERT (ENTIER xxx = LONG LONG 3 AND ENTIER yyy = LONG LONG 3)
+      ASSERT (ENTIER xxx = LONG LONG 3 AND ENTIER yyy = LONG LONG 3);
+      ASSERT (ENTIER x = 3 AND FLOOR y = 3);
+      ASSERT (ENTIER xx = LONG 3 AND FLOOR yy = LONG 3);
+      ASSERT (ENTIER xxx = LONG LONG 3 AND FLOOR yyy = LONG LONG 3)
 END