[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] A double-to-float conversion bug
From: |
Viktor M |
Subject: |
[Tinycc-devel] A double-to-float conversion bug |
Date: |
Sun, 30 Jul 2023 16:07:29 +0600 |
Hello everyone. So today I stumbled upon this bug when doing math
involving conversions between float and double. A minimal example:
---
#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 %d %d %d\n", f, v.x, v.y, v.z);
}
int main(void)
{
float f = 5;
double d = f;
func(d, vec());
return 0;
}
---
The code should print this:
5.000000 0 0 1
but it prints garbage in the first value like this:
-85964.625000 0 0 1
I've tried Linux x86_64 and both mob branch and 0.9.27 release.
tcc -run also fails.
I hope there is an easy fix for this. Thanks.