Skip to content

Repr value for nan #3034

Closed
Closed

Description

@DimitrisJim

In Python:

>>> repr(float('nan'))
'nan'

while in RustPython:

>>>>> repr(float('nan'))
'NaN'

slight incompatibility but it is actually tested for in cmath.

Activity

  1. ShadowJonathan commented on Sep 10, 2021

    @ShadowJonathan

    (TIL NaN is lowercase in repr in python)

  2. DimitrisJim commented on Sep 10, 2021

    @DimitrisJim
    MemberAuthor

    C also displays it as 'nan' if I'm not mistaken. I always remember seeing 'NaN' in Javascript tbh and Rust seems to follow that. Either way, 'NaN' always seemed weird to me, either capitalize em all or don't, why is a being left out like that? No respect for poor a.

    Edit: Seems like the situation is trickier when Wikipedia has an entire subsection dedicated to how NAN is displayed.

  3. Codemonk-adi commented on Sep 15, 2021

    @Codemonk-adi
    Contributor

    @DimitrisJim I would like to work on it
    would you pls guide me a bit?

  4. DimitrisJim commented on Sep 15, 2021

    @DimitrisJim
    MemberAuthor

    Yes! Take a look at float's repr function. This calls another function to handle formatting for the different values that might be passed in. Take a look there and try and find out which case Nan/Inf fall under and what you'd need to do.

  5. Codemonk-adi commented on Sep 16, 2021

    @Codemonk-adi
    Contributor

    RustPython/Lib/reprlib.py

    s = builtins.repr(x)
    # Bugs in x.__repr__() can cause arbitrary
    # exceptions -- then make up something
    
    

    repr(float('nan'))
    returns the builtin repr function called with float('nan')

    I am stuck here...

  6. DimitrisJim commented on Sep 16, 2021

    @DimitrisJim
    MemberAuthor

    Hey @Codemonk-adi, not sure what you mean here. Are you looking inside the implementation of repr for PyFloat? You can always fire up a debugger and get through stepping your way until the end (it takes some getting used to but its worth it).

  7. Codemonk-adi commented on Sep 16, 2021

    @Codemonk-adi
    Contributor

    @DimitrisJim I am sorrry to bother you again, but I am unable to use the debugger, when I run the debug option on vscode it opens an rust python interpreter, and I do enter debugging mode in vscode but the buttons are disabled.

  8. DimitrisJim commented on Sep 16, 2021

    @DimitrisJim
    MemberAuthor

    @Codemonk-adi hop on over to gitter if you can. This way I can help you further w/o notifying watchers.

  9. DimitrisJim commented on Sep 22, 2021

    @DimitrisJim
    MemberAuthor

    closed with #3103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions