Jump to page: 1 2 3
Thread overview
[Issue 3632] New: modify float is float to do a bitwise compare
Dec 19, 2009
Don
Jun 15, 2011
yebblies
Jun 26, 2011
Walter Bright
Jun 26, 2011
kennytm@gmail.com
Jun 27, 2011
kennytm@gmail.com
Jun 27, 2011
yebblies
Jun 27, 2011
Walter Bright
Jun 27, 2011
Walter Bright
Jun 28, 2011
yebblies
Jun 28, 2011
Walter Bright
Jun 28, 2011
yebblies
Jun 28, 2011
Don
Jun 28, 2011
Walter Bright
Jun 28, 2011
Don
Feb 16, 2012
yebblies
Feb 16, 2012
yebblies
Feb 18, 2012
Walter Bright
Feb 18, 2012
yebblies
Apr 27, 2012
Walter Bright
Jan 17, 2013
yebblies
December 18, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3632

           Summary: modify float is float to do a bitwise compare
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: schveiguy@yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy@yahoo.com> 2009-12-18 12:04:05 PST ---
I was trying to test that my array append code is working properly.  In order to do this, I want to verify that when I set the length to a larger number that the additional space is filled with T.init

This test works great for most all types except floating point:

assert(a[$-1] is T.init)

It was pointed out that Phobos has isIdentical, but that doesn't work with literals for some reason:

float a;
assert(isIdentical(a, float.init)) // fails!

But it shouldn't be this hard.  Why does 'is' do a bitwise compare for everything *except* floating point numbers?  I understand that the spec states that is converts to == for builtin types, but it seems inconsistent because == for all builtin types except floating point *is* a bitwise compare.  It seems there is no easy way to get a bitwise compare for floating points, and the method provided doesn't work properly.  It should be braindead simple to get the compiler to do a bitwise compare.

I propose that for floating point types, x is y be equivalent to a bitwise compare.  It is easy to say in the spec "x is y does a bitwise compare, which for all builtin types except for floating point types is equivalent to equality"

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 19, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3632


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2009-12-18 22:49:41 PST ---
(In reply to comment #0)
> It was pointed out that Phobos has isIdentical, but that doesn't work with literals for some reason:
> 
> float a;
> assert(isIdentical(a, float.init)) // fails!

That's because of the recently discovered NaN bug; the code generated for uninitialized floats and doubles needs to change. It's not a problem with isIdentical.

> But it shouldn't be this hard.  Why does 'is' do a bitwise compare for everything *except* floating point numbers?

> I propose that for floating point types, x is y be equivalent to a bitwise compare.  It is easy to say in the spec "x is y does a bitwise compare, which for all builtin types except for floating point types is equivalent to equality"

I think this would be a good idea. I've thought that several times myself. I created the isIdentical() function because I think there's a need for it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 15, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |yebblies@gmail.com


--- Comment #2 from yebblies <yebblies@gmail.com> 2011-06-14 23:50:06 PDT ---
Possible implementation. https://github.com/D-Programming-Language/dmd/pull/126

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2011-06-25 23:20:33 PDT ---
https://github.com/D-Programming-Language/dmd/commit/0d93cf4333df6e167f9027eb1a4b0aa9a940ff19

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #4 from bearophile_hugs@eml.cc 2011-06-26 00:49:51 PDT ---
Do you know what's missing in the list of bug 3981 ?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632


kennytm@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |kennytm@gmail.com
         Resolution|FIXED                       |


--- Comment #5 from kennytm@gmail.com 2011-06-26 01:37:29 PDT ---
This is *not yet fixed*. The current implementation in DMD


           real_t v1 = e1->toReal();
           real_t v2 = e2->toReal();
           cmp = !memcmp(&v1, &v2, sizeof(real_t));


will not work, at least on OS X, because while 'real_t' ('long double') is only
a 80-bit floating point number (occupying 10 bytes), with alignment
'sizeof(real_t)' will take 16 bytes. The extra 6 bytes of paddings are often
filled with garbage. This makes even

       4.0 is 4.0

to return 'false'.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632


kennytm@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #6 from kennytm@gmail.com 2011-06-27 07:21:00 PDT ---
https://github.com/D-Programming-Language/dmd/commit/32740

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


--- Comment #7 from yebblies <yebblies@gmail.com> 2011-06-27 08:19:40 PDT ---
Reopening as the commit above will cause the following assert to fail: static assert(real.init !is real.nan);

And the padding issue has only been fixed for the compile time evaluation, not runtime.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #8 from Walter Bright <bugzilla@digitalmars.com> 2011-06-27 11:32:17 PDT ---
(In reply to comment #7)
> Reopening as the commit above will cause the following assert to fail: static assert(real.init !is real.nan);

This is intended. All nans are regarded as the same (even signalling and
non-signalling).

> And the padding issue has only been fixed for the compile time evaluation, not runtime.

You're right.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #9 from bearophile_hugs@eml.cc 2011-06-27 13:33:12 PDT ---
(In reply to comment #8)

> This is intended. All nans are regarded as the same (even signalling and
> non-signalling).

So we have to use std.math.isIdentical() to tell apart floating point values on the base of the their bit patterns.

Related: I think almost no one uses the NaN payloads because (beside being a niche need) almost no language gives easy and explicit support to manage those payloads (while in std.math there are functions like getNaNPayload).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2 3