Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

numberToRangedRational: fix edge cases for exp ≈ (maxBound :: Int) #192

Copy link
Copy link

Description

@frasertweedale
Issue body actions

Motivation

numberToRangedRational: fix edge cases for exp ≈ (maxBound :: Int)

Currently a negative exponent less than minBound :: Int results in
Infinity, which is very surprising and obviously wrong.

λ> read "1e-9223372036854775808" :: Double                          
0.0                                                                 
λ> read "1e-9223372036854775809" :: Double                          
Infinity                                                            

There is a further edge case where the exponent can overflow when
increased by the number of tens places in the integer part, or
underflow when decreased by the number of leading zeros in the
fractional part if the integer part is zero:

λ> read "10e9223372036854775807" :: Double                          
0.0                                                                 
λ> read "0.01e-9223372036854775808" :: Double                       
Infinity                                                            

Proposal

Fix these bugs. The exponent should not wrap and return Infinity (in case of underflow) or 0 (in case of overflow).
There is a merge request.

Impact

This improves the accuracy of floating point parsing on some extreme cases. Most ordinary programs or use cases are not likely to be affected. Users that are affected would presumably be pleased with this change.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedApproved by CLC voteApproved by CLC votebase-4.20Implemented in base-4.20 (GHC 9.10)Implemented in base-4.20 (GHC 9.10)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.