mixed precision

2023-12-25 17:32:00

a.c

void main()
{
        static long l = -2L;
        static double d = 2.2;
        static float f = 2.2;
        d /= f;
        printf("%ld\n",(l));
        printf("%lf\n",d);
        printf("%lf\n",(l -= d));
        l -= d;
        l -= d;
        l -= d;
        printf("hello 3 times\n");
        printf("%ld\n",l);
}
gcc -O0 -g a.c

result:

-2
1.000000
1.000000
hello 3 times
-2

reason:

(gdb) p d
$2 = 0.99999997832558429
(gdb)

l -= d
	l convert to double
	two double substraction
	convert to long

文章来源:https://blog.csdn.net/qq_38963393/article/details/135203990
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。