(* LowShort.mod provides access to limits of the gm2 SHORTREAL. Copyright (C) 2010-2024 Free Software Foundation, Inc. Contributed by Gaius Mulley . This file is part of GNU Modula-2. GNU Modula-2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Under Section 7 of GPL version 3, you are granted additional permissions described in the GCC Runtime Library Exception, version 3.1, as published by the Free Software Foundation. You should have received a copy of the GNU General Public License and a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . *) IMPLEMENTATION MODULE LowShort ; FROM SYSTEM IMPORT ADDRESS ; FROM Builtins IMPORT ilogbf, modff, signbitf, scalbnf, huge_valf, nextafterf ; FROM dtoa IMPORT Mode, strtod, dtoa ; FROM libc IMPORT free ; FROM RealMath IMPORT power ; FROM ConvStringReal IMPORT RealToFloatString ; FROM StringConvert IMPORT ToSigFig ; FROM EXCEPTIONS IMPORT ExceptionSource, AllocateSource, RAISE, CurrentNumber, IsCurrentSource, IsExceptionalExecution ; FROM DynamicStrings IMPORT String, InitString, KillString, Slice, Mark, Mult, InitStringCharStar, Length, ConCat, ConCatChar, InitStringChar, string ; TYPE FloatingPointExceptions = (badparam) ; VAR currentmode: Modes ; (* exponent - returns the exponent value of x *) PROCEDURE exponent (x: SHORTREAL) : INTEGER ; BEGIN RETURN ilogbf(x) END exponent ; (* fraction - returns the significand (or significant part) of x *) PROCEDURE fraction (x: SHORTREAL) : SHORTREAL ; BEGIN RETURN scalbnf (x, -ilogbf (x)) END fraction ; (* sign - returns the signum of x. sign(x) = 1.0 for all x>0.0 sign(x) = -1.0 for all x<0.0. may be either -1.0 or 1.0 if x = 0.0 *) PROCEDURE sign (x: SHORTREAL) : SHORTREAL ; BEGIN IF signbitf(x)=0 THEN RETURN 1.0 ELSE RETURN -1.0 END END sign ; (* succ - returns the next value of the type REAL greater than x *) PROCEDURE succ (x: SHORTREAL) : SHORTREAL ; BEGIN RETURN nextafterf(x, huge_valf()) END succ ; (* ulp - returns the value of a unit in the last place of x. So either: ulp(x) = succ(x)-x or ulp(x) = x-pred(x) or both are true. if the value does not exist then an exception is raised. *) PROCEDURE ulp (x: SHORTREAL) : SHORTREAL ; BEGIN IF x