[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] A double-to-float conversion bug
From: |
Vincent Lefevre |
Subject: |
Re: [Tinycc-devel] A double-to-float conversion bug |
Date: |
Sun, 30 Jul 2023 18:27:06 +0200 |
User-agent: |
Mutt/2.2.10+64 (b470a9ad) vl-149028 (2023-06-05) |
On 2023-07-30 16:07:29 +0600, Viktor M wrote:
> Hello everyone. So today I stumbled upon this bug when doing math
> involving conversions between float and double. A minimal example:
[...]
Not really minimal. I could simplify it even further:
#include <stdio.h>
struct V {
int x, y, z;
};
struct V vec(void)
{
return (struct V) { 0, 0, 1 };
}
void func(float f, struct V v)
{
printf("%f\n", f);
}
int main(void)
{
float d = 5.0f;
func(d, vec());
return 0;
}
I get successively on x86_64:
-213.969727
-0.000001
-0.000000
44308718004014403453773152256.000000
Putting the 5.0f in the argument instead of d, or reducing the
struct size, or changing float to double makes the bug disappear.
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)