Skip to content

IEEEReal.setRoundingMode is a no-op on Linux #70

@JohnReppy

Description

@JohnReppy

Version

v110.99.1

Operating System

  • All
  • Linux
  • macOS
  • Windows
  • Other Unix

OS Version

WSL

Processor

x86 (32-bit)

Component

Basis Library

Severity

Minor

Description of the problem

IEEEReal.setRoundingMode is a no-op and does not change the rounding mode.
Additional comments:
This also causes issues the functions:
Real.realTrunc, Real.realCeil, Real.realFloor, Real.realRound
since those functions are implemented in terms of IEEEReal.setRoundingMode.
Note that the default rounding mode is implementation-defined, so one and only one of these functions work properly.

Additionally, if IEEEReal.setRoundingMode is unsupported, an error should be thrown instead of silently doing nothing,
similar to other SML/NJ basis functions which are unimplemented (such as Real.fromDecimal).

Fix:
I was unable to understand how the runtime works,
but I think the C runtime may need to use the pragma
#pragma STDC FENV_ACCESS ON (http://www.cplusplus.com/reference/cfenv/FENV_ACCESS/)

One temporary fix for Real.realFloor would be to implement realFloor f as #whole (Real.split f).

Transcript

- IEEEReal.setRoundingMode IEEEReal.TO_ZERO;
val it = () : unit
- IEEEReal.getRoundingMode ();
val it = TO_NEAREST : IEEEReal.rounding_mode

Expected Behavior

No response

Steps to Reproduce

IEEEReal.setRoundingMode IEEEReal.TO_ZERO;
IEEEReal.getRoundingMode ();

Additional Information

No response

Email address

ssoss@uchicago.edu

Comments from smlnj-gforge

Original smlnj-gforge bug number 314

Submitted via web form by Skye Soss ssoss@uchicago.edu on 2022-06-02 at 19:29:00

Keywords: reals, IEEEReal

comment by @JohnReppy on 2022-06-06 14:37:00 +000 UTC

This problem appears to be specific to Linux (e.g., things work correctly on macOS). It may be because compilers are allowed to ignore the floating-point environment unless the FENV_ACCESS pragma is on.

comment by @JohnReppy on 2022-06-06 15:17:00 +000 UTC

The problem turns out to be that Linux did not support the "fenv.h" API, so it was supposed to use assembly code. Modern Linux does have that include file, so we can just use the library functions.

Fixed for 110.99.3 and 2022.1.

Metadata

Metadata

Assignees

Labels

basis-libproblem with Standard ML Basis librarybugSomething isn't workingfixed-in-110.99.3issues that will be fixed in the 110.99.3 versionfloating-pointproblem related to floating-point operationsgforgebug (or feature request) ported from smlnj-gforge repository

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions