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
"-0".Num isn't negative #5557
Comments
From zefram@fysh.org
It's surprising that that's producing a floating-point positive zero,
-zefram |
From @zoffixznetOn Thu, 11 Aug 2016 09:32:31 -0700, zefram@fysh.org wrote:
Thanks for the report. Are you able to describe any usecases where the string cast resulting in a positive zero as opposed to negative zero creates a problem? The reason we have a negative floating point zero at all is more due to underlying implementations at whose level such zeros are used to signal various exceptions. But such usage isn't needed on Perl 6 level. Looking at the current implementation, fixing the described issue would involve special-casing the .Num string As for what's happening: "-0" gets converted to Numeric under the hood, and the containing numeric is an Int, and there's no Int negative zeros, so you end up with a plain 'ol zero that then gets converted to a Num, without the In the second case you present, the string coersion ends up with an Int, which then is converted to a Num; when So this issue gives us first special-casing: that we need to notify the Numeric conversion that we explicitly want a Num at the end. Now, if you try, you'll notice that '-0e0' also results in a positive zero. This is because that Numeric conversion parses the string in parts, each part being an Int and is parsed using radix_I nqp op, and Ints ain't got negative zeros, so even though the code asks the radix_I op to negate the result if we have a minus, we still end up with a positive zero. So this is the second special case, where we have to check whether we've got a minus and a zero result and we explicitly want a Num as the end result. So considering the impact of the end result that fixes this bug, I'm willing to sacrifice minor inconsistency of string casts never resulting in negative zeros, for the sake of clearer and more performant code, but perhaps I'm missing some viable usecase where string cast to numeric losing the sign of the zero is a problem at the high level that Perl 6 operates in? |
The RT System itself - Status changed from 'new' to 'open' |
From @geekosaurOn Thu, Nov 17, 2016 at 10:13 AM, Zoffix Znet via RT <
IEEE supports negative zero because it is useful when working with limits -- |
From @zoffixznetMore discussion on IRC: https://irclog.perlgeek.de/perl6-dev/2016-11-17#i_13584755 So it seems a fix is indeed needed. |
From zefram@fysh.orgZoffix Znet via RT wrote:
No, that's not what negative zero is about in floating point. (Maybe
Getting the right zero particularly matters in trigonometry and in complex
The above behaviour is correct and desirable. In a situation where the -zefram |
From @duncandAnd here I thought IEEE floats had distinct values to represent overflows and On 2016-11-22 8:19 PM, Zefram wrote:
|
From @geekosaurZefrem and I both misspoke on this, but I clarified on IRC and this was On Tue, Nov 22, 2016 at 11:33 PM, Darren Duncan <darren@darrenduncan.net>
-- |
From zefram@fysh.orgBrandon Allbery via RT wrote:
In which aspect did I misspeak? -zefram |
From @geekosaurOn Wed, Nov 23, 2016 at 1:11 AM, Zefram <zefram@fysh.org> wrote:
iirc underflow doesn't work quite the way either you or Darren said; it's -- |
From @geekosaurAnd my own misspeaking was a slight mis-description of the relevance of On Wed, Nov 23, 2016 at 1:20 AM, Brandon Allbery <allbery.b@gmail.com>
-- |
From zefram@fysh.orgBrandon Allbery wrote:
There is no flag attached to a zero to indicate that it came -zefram |
From @geekosaurOn Wed, Nov 23, 2016 at 1:53 AM, Zefram <zefram@fysh.org> wrote:
A status flag is not attached to a value, it is a processor status flag. -- |
From zefram@fysh.orgBrandon Allbery wrote:
I didn't say that you claimed that, and indeed you hadn't. But the -zefram |
From @zoffixznetOn Thu, 11 Aug 2016 09:32:31 -0700, zefram@fysh.org wrote:
Thank you for the report. This is now fixed \o/ rakudo: |
@zoffixznet - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#128897 (status was 'resolved')
Searchable as RT128897$
The text was updated successfully, but these errors were encountered: