Skip to content

Extend inverse power of 5 table for Real.fromString - #306

Merged
JohnReppy merged 2 commits into
smlnj:mainfrom
DarinM223:fix_real_fromstring
May 12, 2025
Merged

JohnReppy merged 2 commits into
smlnj:mainfrom
DarinM223:fix_real_fromstring

Conversation

@DarinM223

Copy link
Copy Markdown
Contributor

Description

Extend the inverse power of 5 table so that larger negative exponents will not raise a Subscript exception.

Related Issue

Motivation and Context

Real.fromString (Real.toString Real.minPos) raises a Subscript exception. Some codebases like SML.NET parse real constants with SML/NJ's Real.fromString function, and they implement Real.minPos in their basis library as a constant 4.94e~320, so they can't compile with the 2025.1 SML/NJ because that constant goes out of the bounds of the inverse power of 5 table.

The cvt function in the frep-to-real64.sml file is an implementation of s2d in the ryu codebase. In that repository there is a PR that extends the inverse power of 5 table ulfjack/ryu#237. This PR simply uses the numbers in that PR to extend the table.

How Has This Been Tested?

- Real.fromString (Real.toString Real.minPos);
val it = SOME 5E~324 : real option
- Real.minPos;
val it = 5E~324 : real
- Real.fromString (Real.toString Real.minNormalPos);
val it = SOME 2.22507385851E~308 : real option
- Real.minNormalPos;
val it = 2.22507385851E~308 : real
- Real.fromString "4.94e~320";
val it = SOME 4.94E~320 : real option

I'm not too familiar with all the numbers that would hit every inverse power of 5 in the extended table, so there is probably missing cases that would need to be tested here.

@JohnReppy
JohnReppy merged commit f8c86c8 into smlnj:main May 12, 2025
@JohnReppy JohnReppy added the fixed-in-2025.2 Issues that have been closed for the 2025.2 release label Jul 12, 2025
@DarinM223
DarinM223 deleted the fix_real_fromstring branch August 2, 2025 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixed-in-2025.2 Issues that have been closed for the 2025.2 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants