gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in gm2 LowShort.fraction()


From: Nelson H. F. Beebe
Subject: Bug in gm2 LowShort.fraction()
Date: Thu, 1 Feb 2024 06:33:42 -0700

I have been using Modula-2 intensively for the past month as I develop
an interface between that language and a large mathematical library
that I have written.

In the course of that work, I have uncovered several bugs in the
compiler or its module library.  I will report them in separate
messages to this list, because there does not appear to be
a gm2-bugs list in the links at https://lists.nongnu.org/mailman/listinfo.

I have used /usr/bin/gm2 (13.2.0) on Ubuntu 24.04, as well as several
recent snapshots of gcc-13 and gcc-14 that I build roughly monthly
with selection of all supported compilers, including gm2 for Modula-2.

The function LowShort.fraction() is declared in a path like this:

        
$prefix/ashare/gcc/gcc-14-20240107/lib64/gcc/x86_64-pc-linux-gnu/14.0.0/m2/m2iso/LowShort.def

with this text:

        PROCEDURE fraction (x: SHORTREAL): SHORTREAL;
          (* Returns the significand (or significant part) of x *)

Here is a test program that exhibits a bug in that function:

        % cat fractionbug.mod
        MODULE fractionbug;

        FROM NumberIO  IMPORT WriteInt;
        FROM RealInOut IMPORT WriteShortReal;
        FROM StrIO     IMPORT WriteLn, WriteString;

        IMPORT LowShort;

        CONST DIGITS = 9; (* matula(24): decimal digits for exact round-trip 
conversion *)
              WIDTH = DIGITS + 1;

        VAR n : INTEGER;
            x, y, w : SHORTREAL;

        BEGIN
            FOR n := 1 TO 25 DO
                x := VAL(SHORTREAL, n) / 8.0;
                WriteString('x                = ');
                WriteShortReal (x, WIDTH);
                WriteLn;

                y := LowShort.fraction(x);

                WriteString('fraction(x)      = ');
                WriteShortReal (y, WIDTH);
                WriteLn
            END
        END fractionbug.

Here is what happens:

        % gm2 fractionbug.mod && ./a.out
        
../../../../gcc-14-20240114/libgm2/libm2pim/../../gcc/m2/gm2-libs/StringConvert.mod:1069:in
        ToDecimalPlaces has caused assert failed

-------------------------------------------------------------------------------
- Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
- University of Utah                                                          -
- Department of Mathematics, 110 LCB    Internet e-mail: beebe@math.utah.edu  -
- 155 S 1400 E RM 233                       beebe@acm.org  beebe@computer.org -
- Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]