Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 19, 2005 double comparison bug (and bug-fix) | ||||
---|---|---|---|---|
| ||||
<test-code> void main(){ TypeInfo ti = typeid(double); double a = 0, b = .1; assert(ti.compare(&a, &b)<0); } </test-code> This is due to a bug in phobos/std/typeinfo/ti_double.d. <code> #18 int compare(void *p1, void *p2) #19 { #20 return cast(int)(*cast(double *)p1 - *cast(double *)p2); #21 } </code> A quick fix: <code> int compare(void *p1, void *p2) { double d = (*cast(double *)p1 - *cast(double *)p2); return d>0?1:d<0?-1:0; } </code> |
February 19, 2005 Re: double comparison bug (and bug-fix) | ||||
---|---|---|---|---|
| ||||
Posted in reply to zwang | zwang wrote:
> <test-code>
> void main(){
> TypeInfo ti = typeid(double);
> double a = 0, b = .1;
> assert(ti.compare(&a, &b)<0); }
> </test-code>
>
>
> This is due to a bug in phobos/std/typeinfo/ti_double.d.
> <code>
> #18 int compare(void *p1, void *p2)
> #19 {
> #20 return cast(int)(*cast(double *)p1 - *cast(double *)p2);
> #21 }
> </code>
>
> A quick fix:
> <code>
> int compare(void *p1, void *p2)
> {
> double d = (*cast(double *)p1 - *cast(double *)p2);
> return d>0?1:d<0?-1:0;
> }
> </code>
The following files should also be patched similarly:
File ti_double.d:
20 return cast(int)(*cast(double *)p1 - *cast(double *)p2);
File ti_float.d:
20 return cast(int)(*cast(float *)p1 - *cast(float *)p2);
File ti_idouble.d:
20 return cast(int)(*cast(double *)p1 - *cast(double *)p2);
File ti_ifloat.d:
20 return cast(int)(*cast(float *)p1 - *cast(float *)p2);
File ti_ireal.d:
20 return cast(int)(*cast(real *)p1 - *cast(real *)p2);
File ti_real.d:
20 return cast(int)(*cast(real *)p1 - *cast(real *)p2);
|
February 19, 2005 Re: double comparison bug (and bug-fix) | ||||
---|---|---|---|---|
| ||||
Posted in reply to zwang Attachments: | zwang wrote: | zwang wrote: | |> <test-code> |> void main(){ |> TypeInfo ti = typeid(double); |> double a = 0, b = .1; |> assert(ti.compare(&a, &b)<0); } |> </test-code> |> |> |> This is due to a bug in phobos/std/typeinfo/ti_double.d. |> <code> |> #18 int compare(void *p1, void *p2) |> #19 { |> #20 return cast(int)(*cast(double *)p1 - *cast(double *)p2); |> #21 } |> </code> |> |> A quick fix: |> <code> |> int compare(void *p1, void *p2) |> { |> double d = (*cast(double *)p1 - *cast(double *)p2); |> return d>0?1:d<0?-1:0; |> } |> </code> float, double and real are known bugs. Wasn't there some patch floating around half a year ago?!? | The following files should also be patched similarly: | File ti_idouble.d: | 20 return cast(int)(*cast(double *)p1 - *cast(double *)p2); | File ti_ifloat.d: | 20 return cast(int)(*cast(float *)p1 - *cast(float *)p2); | File ti_ireal.d: | 20 return cast(int)(*cast(real *)p1 - *cast(real *)p2); Added to DStress as http://dstess.kuehne.cn/run/sort_13.d http://dstess.kuehne.cn/run/sort_14.d http://dstess.kuehne.cn/run/sort_15.d Thomas |
February 19, 2005 Re: double comparison bug (and bug-fix) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kühne | Thomas Kühne wrote:
> float, double and real are known bugs.
> Wasn't there some patch floating around half a year ago?!?
Sorry for my unawareness of these early bug reports.
I still wonder why Phobos isn't patched yet.
|
Copyright © 1999-2021 by the D Language Foundation