Jump to page: 1 237  
Page
Thread overview
Always false float comparisons
May 09, 2016
Walter Bright
May 09, 2016
qznc
May 09, 2016
Walter Bright
May 09, 2016
Jens Mueller
May 09, 2016
Chris
May 09, 2016
Walter Bright
May 09, 2016
John Colvin
May 09, 2016
qznc
May 09, 2016
Walter Bright
May 12, 2016
Marco Leise
May 13, 2016
Walter Bright
May 13, 2016
Timon Gehr
May 13, 2016
Walter Bright
May 14, 2016
Timon Gehr
May 14, 2016
Timon Gehr
May 14, 2016
Timon Gehr
May 14, 2016
Walter Bright
May 14, 2016
QAston
May 14, 2016
Walter Bright
May 14, 2016
jmh530
May 14, 2016
Walter Bright
May 14, 2016
John Colvin
May 14, 2016
Walter Bright
May 14, 2016
Walter Bright
May 16, 2016
Joakim
May 18, 2016
Joakim
May 18, 2016
Joakim
May 18, 2016
Joakim
May 18, 2016
Matthias Bentrup
May 18, 2016
Joakim
May 18, 2016
Iain Buclaw
May 18, 2016
Walter Bright
May 15, 2016
Walter Bright
May 15, 2016
Adam D. Ruppe
May 15, 2016
Walter Bright
May 15, 2016
poliklosio
May 15, 2016
Walter Bright
May 16, 2016
Manu
May 16, 2016
Walter Bright
May 14, 2016
Era Scarecrow
May 14, 2016
Binarydepth
May 14, 2016
Era Scarecrow
May 15, 2016
Era Scarecrow
May 15, 2016
Walter Bright
May 15, 2016
Walter Bright
May 15, 2016
Walter Bright
May 16, 2016
Walter Bright
May 16, 2016
Marco Leise
May 16, 2016
Timon Gehr
May 16, 2016
Walter Bright
May 16, 2016
Walter Bright
May 15, 2016
Era Scarecrow
May 15, 2016
Walter Bright
May 15, 2016
Seb
May 16, 2016
Era Scarecrow
May 16, 2016
Walter Bright
May 16, 2016
Iain Buclaw
May 16, 2016
Iain Buclaw
May 16, 2016
Iain Buclaw
May 16, 2016
Iain Buclaw
May 16, 2016
deadalnix
[OT] Re: Always false float comparisons
May 16, 2016
Max Samukha
May 17, 2016
Walter Bright
May 16, 2016
Walter Bright
May 16, 2016
Walter Bright
May 16, 2016
Walter Bright
May 16, 2016
Walter Bright
May 17, 2016
Era Scarecrow
May 17, 2016
Walter Bright
May 17, 2016
Manu
May 16, 2016
Jonathan M Davis
May 17, 2016
Era Scarecrow
May 17, 2016
Marco Leise
May 18, 2016
Timon Gehr
Jun 28, 2017
Timon Gehr
May 14, 2016
Binarydepth
May 09, 2016
ZombineDev
May 09, 2016
Walter Bright
Jun 29, 2017
Ecstatic Coder
Jun 29, 2017
ag0aep6g
Jun 30, 2017
Ecstatic Coder
Jun 30, 2017
Ecstatic Coder
Jun 30, 2017
ag0aep6g
Jun 30, 2017
Ecstatic Coder
May 09, 2016
Nordlöw
May 09, 2016
Nordlöw
May 09, 2016
Walter Bright
May 09, 2016
Temtaime
May 10, 2016
Nordlöw
May 09, 2016
Nordlöw
May 09, 2016
Marco Leise
May 09, 2016
Ethan Watson
May 09, 2016
Walter Bright
May 09, 2016
Ethan Watson
May 09, 2016
Xinok
May 09, 2016
tsbockman
May 09, 2016
Xinok
May 09, 2016
tsbockman
May 09, 2016
Walter Bright
May 09, 2016
John Colvin
May 17, 2016
Timon Gehr
May 10, 2016
Observer
May 09, 2016
Walter Bright
May 09, 2016
tsbockman
May 09, 2016
tsbockman
May 11, 2016
Kagamin
May 09, 2016
Walter Bright
May 10, 2016
Xinok
May 10, 2016
Walter Bright
May 09, 2016
Jonathan M Davis
May 09, 2016
Marco Leise
May 10, 2016
Manu
May 10, 2016
Walter Bright
May 11, 2016
Jacob Carlborg
May 12, 2016
Nordlöw
May 12, 2016
Nordlöw
May 09, 2016
Joe Duarte
May 10, 2016
Manu
May 10, 2016
Manu
May 10, 2016
Walter Bright
May 11, 2016
Manu
May 12, 2016
Walter Bright
May 12, 2016
Manu
May 12, 2016
Walter Bright
May 12, 2016
Guillaume Chatelet
May 12, 2016
Walter Bright
May 12, 2016
H. S. Teoh
May 12, 2016
Guillaume Chatelet
May 12, 2016
Walter Bright
May 12, 2016
ag0aep6g
May 12, 2016
ag0aep6g
May 12, 2016
Walter Bright
May 12, 2016
Marco Leise
May 12, 2016
Ethan Watson
May 12, 2016
Ethan Watson
May 12, 2016
Walter Bright
May 12, 2016
Marco Leise
May 13, 2016
Walter Bright
May 13, 2016
Jack Stouffer
May 13, 2016
xenon325
May 13, 2016
Walter Bright
May 15, 2016
deadalnix
May 15, 2016
Max Samukha
May 13, 2016
Manu
May 13, 2016
Walter Bright
May 13, 2016
Walter Bright
May 14, 2016
Walter Bright
May 16, 2016
Manu
May 16, 2016
Walter Bright
May 16, 2016
Manu
May 16, 2016
Walter Bright
May 16, 2016
Manu
May 16, 2016
Walter Bright
May 17, 2016
Timon Gehr
May 17, 2016
deadalnix
May 18, 2016
Timon Gehr
May 17, 2016
Walter Bright
May 18, 2016
H. S. Teoh
May 18, 2016
Walter Bright
May 18, 2016
Ethan Watson
May 18, 2016
Walter Bright
May 18, 2016
Ethan Watson
May 18, 2016
Walter Bright
May 18, 2016
Ethan Watson
May 18, 2016
Walter Bright
May 18, 2016
Ethan Watson
May 18, 2016
Walter Bright
May 18, 2016
Ethan Watson
May 20, 2016
Walter Bright
May 18, 2016
ixid
May 18, 2016
Manu
May 18, 2016
ixid
May 18, 2016
Manu
May 18, 2016
deadalnix
May 18, 2016
Walter Bright
May 18, 2016
Johannes Pfau
May 18, 2016
deadalnix
May 18, 2016
Johannes Pfau
May 18, 2016
deadalnix
May 18, 2016
jmh530
May 18, 2016
deadalnix
May 18, 2016
jmh530
May 18, 2016
Walter Bright
May 18, 2016
deadalnix
May 18, 2016
Walter Bright
May 18, 2016
Walter Bright
May 18, 2016
H. S. Teoh
May 18, 2016
H. S. Teoh
May 18, 2016
Manu
May 18, 2016
Walter Bright
May 18, 2016
jmh530
May 18, 2016
Era Scarecrow
May 18, 2016
tsbockman
May 18, 2016
Era Scarecrow
May 18, 2016
tsbockman
May 18, 2016
Era Scarecrow
May 18, 2016
tsbockman
May 18, 2016
Era Scarecrow
May 18, 2016
tsbockman
May 18, 2016
Timon Gehr
May 19, 2016
Joakim
May 19, 2016
Joakim
May 19, 2016
Joakim
May 19, 2016
Joakim
May 19, 2016
Timon Gehr
May 20, 2016
Joakim
May 20, 2016
Timon Gehr
May 20, 2016
Joakim
May 21, 2016
Timon Gehr
Aug 22, 2016
Joakim
Aug 23, 2016
Timon Gehr
May 20, 2016
Johan Engelen
May 21, 2016
Timon Gehr
May 19, 2016
Walter Bright
May 19, 2016
Max Samukha
May 20, 2016
Walter Bright
May 21, 2016
Timon Gehr
May 19, 2016
Timon Gehr
May 20, 2016
Walter Bright
May 20, 2016
Timon Gehr
May 20, 2016
HorseWrangler
May 20, 2016
Tobias Müller
May 20, 2016
Tobias M
May 20, 2016
Walter Bright
May 21, 2016
Tobias Müller
May 21, 2016
Walter Bright
May 21, 2016
Tobias M
May 21, 2016
Walter Bright
May 21, 2016
Tobias M
May 21, 2016
Timon Gehr
May 21, 2016
Tobias M
May 21, 2016
Timon Gehr
May 21, 2016
Timon Gehr
May 21, 2016
Walter Bright
May 21, 2016
Fool
May 21, 2016
Timon Gehr
May 21, 2016
Max Samukha
May 19, 2016
Timon Gehr
May 21, 2016
Fool
May 16, 2016
Max Samukha
May 16, 2016
Manu
May 16, 2016
Timon Gehr
May 17, 2016
Max Samukha
May 21, 2016
Timon Gehr
May 16, 2016
Iain Buclaw
May 16, 2016
Iain Buclaw
May 16, 2016
Walter Bright
May 16, 2016
Walter Bright
May 13, 2016
Iain Buclaw
May 16, 2016
Manu
May 16, 2016
Walter Bright
May 16, 2016
Manu
May 16, 2016
Walter Bright
May 16, 2016
Manu
May 16, 2016
Walter Bright
May 16, 2016
Manu
May 16, 2016
Walter Bright
May 16, 2016
Manu
May 16, 2016
Walter Bright
May 16, 2016
Mike James
May 16, 2016
deadalnix
May 16, 2016
Walter Bright
May 16, 2016
Walter Bright
May 17, 2016
Manu
May 17, 2016
Ethan Watson
May 17, 2016
Walter Bright
May 17, 2016
Manu
May 16, 2016
Walter Bright
May 16, 2016
Walter Bright
May 16, 2016
jmh530
May 16, 2016
Walter Bright
May 16, 2016
jmh530
May 17, 2016
Timon Gehr
May 17, 2016
Ethan Watson
May 17, 2016
jmh530
May 16, 2016
H. S. Teoh
May 16, 2016
Walter Bright
May 16, 2016
Guillaume Piolat
May 17, 2016
Walter Bright
May 16, 2016
Daniel Murphy
May 16, 2016
Timon Gehr
May 16, 2016
Iain Buclaw
May 16, 2016
Walter Bright
May 17, 2016
Matthias Bentrup
May 16, 2016
Walter Bright
May 17, 2016
Wyatt
May 17, 2016
Walter Bright
May 17, 2016
Manu
May 16, 2016
Max Samukha
May 16, 2016
Ethan Watson
May 16, 2016
Iain Buclaw
May 16, 2016
Manu
May 16, 2016
Marco Leise
May 09, 2016
Don Clugston pointed out in his DConf 2016 talk that:

    float f = 1.30;
    assert(f == 1.30);

will always be false since 1.30 is not representable as a float. However,

    float f = 1.30;
    assert(f == cast(float)1.30);

will be true.

So, should the compiler emit a warning for the former case?
May 09, 2016
On Monday, 9 May 2016 at 09:10:19 UTC, Walter Bright wrote:
> Don Clugston pointed out in his DConf 2016 talk that:
>
>     float f = 1.30;
>     assert(f == 1.30);
>
> will always be false since 1.30 is not representable as a float. However,
>
>     float f = 1.30;
>     assert(f == cast(float)1.30);
>
> will be true.
>
> So, should the compiler emit a warning for the former case?

What is the actual reason for the mismatch?

Does f lose precision as a float, while the 1.30 literal is a more precise double/real? Comparing float and double might be worth a warning.

Does it encode the two literals differently? If so, why?
May 09, 2016
On Monday, 9 May 2016 at 09:10:19 UTC, Walter Bright wrote:
> So, should the compiler emit a warning for the former case?

I'm not for a compiler change. IMO a library called std.sanity_float with a equal and a notequal function would be better.
May 09, 2016
Walter Bright via Digitalmars-d wrote:
> Don Clugston pointed out in his DConf 2016 talk that:
> 
>     float f = 1.30;
>     assert(f == 1.30);
> 
> will always be false since 1.30 is not representable as a float. However,
> 
>     float f = 1.30;
>     assert(f == cast(float)1.30);
> 
> will be true.
> 
> So, should the compiler emit a warning for the former case?

Since

assert(f == 1.30f);

passes I find the root cause lies in the implicit type conversion from
float to double. Warning for those comparisons should be fine. Shouldn't
mix them anyway.
I wonder what's the difference between 1.30f and cast(float)1.30.

Jens
May 09, 2016
On Monday, 9 May 2016 at 10:16:54 UTC, Jens Mueller wrote:
> Walter Bright via Digitalmars-d wrote:
>> Don Clugston pointed out in his DConf 2016 talk that:
>> 
>>     float f = 1.30;
>>     assert(f == 1.30);
>> 
>> will always be false since 1.30 is not representable as a float. However,
>> 
>>     float f = 1.30;
>>     assert(f == cast(float)1.30);
>> 
>> will be true.
>> 
>> So, should the compiler emit a warning for the former case?
>
> Since
>
> assert(f == 1.30f);
>
> passes I find the root cause lies in the implicit type conversion from
> float to double. Warning for those comparisons should be fine. Shouldn't
> mix them anyway.
> I wonder what's the difference between 1.30f and cast(float)1.30.
>
> Jens

+1
May 09, 2016
On Monday, 9 May 2016 at 09:10:19 UTC, Walter Bright wrote:
> Don Clugston pointed out in his DConf 2016 talk that:
>
>     float f = 1.30;
>     assert(f == 1.30);
>
> will always be false since 1.30 is not representable as a float. However,
>
>     float f = 1.30;
>     assert(f == cast(float)1.30);
>
> will be true.
>
> So, should the compiler emit a warning for the former case?

Yes, I think it is a good idea, just like emitting a warning for mismatched signed/unsigned comparison.
May 09, 2016
On 5/9/2016 2:25 AM, qznc wrote:
> What is the actual reason for the mismatch?

floats cannot represent 1.30 exactly, and promoting it to a double gives a different result than 1.30 as a double.

May 09, 2016
On 5/9/2016 3:16 AM, Jens Mueller via Digitalmars-d wrote:
> passes I find the root cause lies in the implicit type conversion from
> float to double.

That isn't going to change.

> Warning for those comparisons should be fine. Shouldn't mix them anyway.

Too onerous.

> I wonder what's the difference between 1.30f and cast(float)1.30.

There isn't one.

May 09, 2016
On Monday, 9 May 2016 at 09:10:19 UTC, Walter Bright wrote:
> So, should the compiler emit a warning for the former case?

Yes, please. I would prefer, at least, a warning flag for that.
May 09, 2016
On Monday, 9 May 2016 at 09:10:19 UTC, Walter Bright wrote:
> So, should the compiler emit a warning for the former case?

Would that include comparison of variables only aswell?

    float f = 1.3;
    double d = 1.3;
    assert(f == d); // compiler warning
« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10 11