Ticket #370 (new bug)

Opened 13 years ago

Last modified 11 years ago

Rounding Inf and NaN

Reported by: dukeleto Owned by: Paul C. Anagnostopoulos
Priority: normal Milestone:
Component: core Version: trunk
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:

Description

$ ./perl6

say ceiling(NaN)

-2147483648

say floor(NaN)

-2147483648

say floor(Inf)

-2147483648

say ceiling(Inf)

-2147483648

Attachments

rounding-nan-test.patch Download (444 bytes) - added by dukeleto 13 years ago.
Attempt at testing rounding of NaN, but I get runtime error about 'attempt to access code outside of current code segment'
complete_error.txt Download (379 bytes) - added by dukeleto 13 years ago.
Complete Error message of the failing example test
passing-nan-tests.patch Download (1.0 KB) - added by dukeleto 13 years ago.
Passing NaN-rounding-related tests

Change History

Changed 13 years ago by dukeleto

Attempt at testing rounding of NaN, but I get runtime error about 'attempt to access code outside of current code segment'

Changed 13 years ago by dukeleto

Complete Error message of the failing example test

Changed 13 years ago by dukeleto

Passing NaN-rounding-related tests

Changed 13 years ago by dukeleto

After a little more digging, it seems that Rakudo's floor() passes the string 'NaN' down to Parrot's rounding functions, but PASM's floor() and cousins only act on numeric registers, so 'NaN' and 'Inf' turn into some machine-dependent integer. Code written in PIR works just fine though.

Changed 13 years ago by coke

  • status changed from new to closed
  • resolution set to invalid

Per original poster, this is a rakudo issue, not a parrot issue; created a ticket for rakudo at

 http://rt.perl.org/rt3/Ticket/Display.html?id=63440

which just points back here for now. Resolving ticket.

Changed 13 years ago by NotFound

A shortened version of the patch for the arithmetic test added in r36971

Changed 13 years ago by pmichaud

  • status changed from closed to reopened
  • lang perl6 deleted
  • component changed from none to core
  • resolution invalid deleted

(reopening ticket with message I sent to parrot-dev earlier this week)

FWIW, I don't entirely agree with the premise that this is strictly a Rakudo bug. I find that Parrot has some undefined behavior when dealing with NaN, Inf, and integers, and little documentation to indicate what the expected behavior (if any) should be. As an example:

    $ cat x.pir
    .sub 'main'
        $N0 = 3.5
        say $N0
        $I0 = floor $N0
        say $I0

        $N0 = 'Inf'
        say $N0
        $I0 = floor $N0
        say $I0
    .end

    $ ./parrot x.pir
    3.5
    3
    Inf
    -2147483648
    $

On my machine, Parrot seems to always treat an integer conversion of any infinity as -2147483648. Better would seem to be to throw a range exception or the like, instead of silently converting to a non-infinite integer value.

Pm

Changed 12 years ago by dukeleto

  • status changed from reopened to new
  • owner set to dukeleto

Changed 12 years ago by dukeleto

  • status changed from new to assigned

Changed 12 years ago by dukeleto

The example that pmichaud++ gave is now a TODO test in t/op/arithmetics.t

Changed 12 years ago by dukeleto

Tests relating to Inf/NaN now live in t/op/inf_nan.t . I have added many tests recently , and the same bug that pmichaud++ describes happens to the fdiv, mod and cmod functions.

Changed 11 years ago by Paul C. Anagnostopoulos

  • owner changed from dukeleto to Paul C. Anagnostopoulos
  • status changed from assigned to new
Note: See TracTickets for help on using tickets.