[COMMITTED] a68: fix float standard conversion routine
Jose E. Marchesi
jemarch@gnu.org
Sat Mar 14 16:22:03 GMT 2026
This commit fixes the implementation of the `float' standard
conversion routine, by amending a typo that originates in the Revised
Report. It also makes the routine to properly handle short short and
short int arguments.
Signed-off-by: Jose E. Marchesi <jemarch@gnu.org
libga68/ChangeLog
* standard.a68.in (float): Fix typo from RR and handle short* int
arguments properly.
gcc/testsuite/ChangeLog
* algol68/execute/float-1.a68: New test.
---
gcc/testsuite/algol68/execute/float-1.a68 | 3 +++
libga68/standard.a68.in | 13 +++++++++----
2 files changed, 12 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/algol68/execute/float-1.a68
diff --git a/gcc/testsuite/algol68/execute/float-1.a68 b/gcc/testsuite/algol68/execute/float-1.a68
new file mode 100644
index 00000000000..1c3531bfe87
--- /dev/null
+++ b/gcc/testsuite/algol68/execute/float-1.a68
@@ -0,0 +1,3 @@
+begin assert(float(123.4567,12,5,2) = "+12.34567e+1");
+ assert(float(123.4567,-10,5,-1) = " 1.23457e2")
+end
diff --git a/libga68/standard.a68.in b/libga68/standard.a68.in
index 6d543e7cff8..5246679fa9f 100644
--- a/libga68/standard.a68.in
+++ b/libga68/standard.a68.in
@@ -114,21 +114,26 @@ def
case v in
{iter L {} {long} {long long}}
{iter L_ {} {long_} {long_long_}}
+ {iter S {} {LENG} {LENG LENG}}
({L} real x):
if int before = ABS width - ABS exp - (after /= 0 | after+1 | 0) - 2;
SIGN before + SIGN after > 0
then string s, {L} real y := ABS x, int p := 0;
{L_}standardize (y, before, after, p);
- s := fixed (SIGN (x * y), SIGN width * (ABS width - ABS exp - 1),
- after) + "*^" + whole (p, exp);
+ s := fixed ({S} SIGN x * y, SIGN width * (ABS width - ABS exp - 1),
+ after) + "e" + whole (p, exp);
if exp = 0 OR char_in_string (errorchar, loc int, s)
then float (x, width, (after /= 0 | after-1 | 0),
(exp > 0 | exp+1 | exp-1))
else s
fi
else { XXX undefined } skip; ABS width * errorchar
- fi,
- ({L} int x): float ({L} real (x), width, after, exp)
+ fi
+ {reti {,}}
+ ,
+ {iter L {short short} {short} {} {long} {long long}}
+ {iter R {LENG LENG} {LENG} {} {} {}}
+ ({L} int x): float ({L} real ({R} x), width, after, exp)
{reti {,}}
esac;
--
2.39.5
More information about the Algol68
mailing list