Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: issue #4713 (print special float! not right) #4714

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bitbegin
Copy link
Collaborator

@bitbegin bitbegin commented Nov 9, 2020

No description provided.

@qtxie
Copy link
Contributor

qtxie commented Nov 9, 2020

https://en.wikipedia.org/wiki/IEEE_754-1985, All NaNs in IEEE 754-1985 have this format:

sign = either 0 or 1.
biased exponent = all 1 bits.
fraction = anything except all 0 bits (since all 0 bits represents infinity).

A better test for double float NaN and INF:

if d/2 and 7FF00000h = 7FF00000h [ ;-- if biased exponent all 1 bits, it is INF or NaN
    either all [   ;-- if fraction all 0 bits, it's INF
        zero? d/1
        zero? (d/2 and 000FFFFFh)
    ][
        either zero? (d/2 and 80000000h) [prin "1.#INF"][prin "-1.#INF"] ;-- check sign bit
    ][prin "1.#NaN"] ;-- otherwise NaN
]

@bitbegin
Copy link
Collaborator Author

bitbegin commented Nov 9, 2020

this pr is more simple for me, and can cover all cases

@qtxie
Copy link
Contributor

qtxie commented Nov 9, 2020

It's hard for me to understand the code without explaining the rationale of it in a PR, also no comments in the code.

@dockimbel dockimbel requested a review from qtxie November 9, 2020 09:36
@bitbegin
Copy link
Collaborator Author

@bitbegin
Copy link
Collaborator Author

bitbegin commented Nov 10, 2020

图片

make this check simply, treat both SNAN and QNAN as NAN. +INF/-INF are special cases, so need process first

@qtxie
Copy link
Contributor

qtxie commented Nov 11, 2020

@bitbegin Thanks. In this PR you check those special values by patterns. While I prefer to do the checking by rules. See my first comment. A more lengthy version as below:

  1. if all bits in exponent part are 1, it's a special value (NaN or INF)
  2. if it's special value, check fraction part
  3. if all bits in fraction part are 0, it's a INF, otherwise it's a NaN
  4. if it's a INF, check sign bit to distinguish -INF and +INF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants