Ticket #358 (assigned bug)

Opened 6 years ago

Last modified 3 years ago

complex NaN

Reported by: rurban Owned by: dukeleto
Priority: normal Milestone:
Component: core Version:
Severity: medium Keywords:
Cc: plobsing Language:
Patch status: Platform:

Description (last modified by rurban) (diff)

$ perl6
> say NaN*1i
NaNNaNi

All complex ops with NaN should return NaN.

Check the complex ops with NaN, add tests.

Attachments

tt358-complex-nan.patch Download (10.1 KB) - added by rurban 6 years ago.
unfinished

Change History

Changed 6 years ago by rurban

  • status changed from new to assigned

Changed 6 years ago by rurban

  • description modified (diff)

Changed 6 years ago by rurban

Current situation:

  $P1=new ["Complex"]
  $P2=new ["Complex"]
  $P1="NaN" 
  $P2="i"
  $P2 = mul $P1, $P2
  say $P2

The result is "NaNi", because both parts are treated individually and the plus is dropped from i in the printout.

NaN in the real part will not harm the calculation if the imaginary part in non-NaN: NaN+i * 1-2i = NaN-2i

The string representation of a complex is sprintf("%vg%+vgi", re, im) So NaN-2i is "NaN-2i" and NaN+i is printed as "NaNi"

So NaN * 1i = NaNi

The proposed is the represent a complex with either the real or imaginary part of NaN as "NaN", and do not seperate them.

Changed 6 years ago by rurban

unfinished

Changed 5 years ago by jkeenan

  • component changed from none to core

Changed 5 years ago by dukeleto

  • owner changed from rurban to dukeleto
  • status changed from assigned to new

Changed 5 years ago by dukeleto

  • status changed from new to assigned

Changed 5 years ago by dukeleto

The code snippet

    $P1=new ["Complex"]
    $P1="NaN"

now gives the error

Complex: malformed string
current instr.: 'test_complex_nan' pc 21447 (t/pmc/complex.t:1170)

Changed 5 years ago by dukeleto

    $P1 = new ["Complex"]
    $N0 = 'NaN'
    set $P1, "1 + i"
    $P1 += $N0
    say $P1

prints

NaN+1i

Changed 5 years ago by coke

On Thu, Aug 20, 2009 at 10:26 PM, Parrot<parrot-tickets@lists.parrot.org> wrote:
> #358: complex NaN
> --------------------+-------------------------------------------------------
>  Reporter:  rurban  |       Owner:  dukeleto
>     Type:  bug     |      Status:  assigned
>  Priority:  normal  |   Milestone:
> Component:  core    |     Version:
>  Severity:  medium  |    Keywords:
>     Lang:          |       Patch:
>  Platform:          |
> --------------------+-------------------------------------------------------
>
> Comment(by dukeleto):
>
>  {{{
>     $P1 = new ["Complex"]
>     $N0 = 'NaN'
>     set $P1, "1 + i"
>     $P1 += $N0
>     say $P1
>  }}}
>  prints
>  {{{
>  NaN+1i
>  }}}
>

Should it print Nan+1i or just NaN? (How infectious /is/ Nan?)


-- 
Will "Coke" Coleda

Changed 5 years ago by dukeleto

I am going on the assumption that there "can be only one" NaN. The entity 'NaN' is for encoding the idea that we should represent an invalid arithmetic operation as something special. There is no "real" NaN and "complex" NaN. *All* arithmetic operations, no matter they be real or complex, that contain a NaN should simplify to NaN. The partial patch that was added to this ticket adds some support for parsing complex numbers of the form "NaN+2*i" and such, but there are still all kinds of other ways that you can make either the real or imaginary part of the resulting number NaN that does not require parsing a string, and these are the cases where we still have bugs.

Also, the patch attached is quite old and the tests no longer compile, but it is a good start.

Changed 4 years ago by jkeenan

  • cc plobsing added

plobsing,

As with TT #954, based on your work around infnan, can you evaluate the issues discussed in this ticket?

Thank you very much.

kid51

Changed 3 years ago by dukeleto

We need a branch that has tests for this bug. It is still present.

Note: See TracTickets for help on using tickets.