Плавающе-точечное
Nov. 18th, 2013 12:51 amВ какой-то мере навеяно постом
Что произойдет в вашей системе и что, по-вашему, должно произойти при попытке компиляции (и, если компиляция была/должна быть успешной, то запуска) следующей программы на Си:
#include <stdio.h>
main() {
printf("%d %d %d\n", (int)(-1.0/0.0), (int)(0.0/0.0), (int)(1.0/0.0));
}
no subject
Date: 2013-11-18 09:22 am (UTC)no subject
Date: 2013-11-18 04:28 pm (UTC)no subject
Date: 2013-11-19 06:14 am (UTC)C99:
The result of the / operator is the quotient from the division of the first operand by the second; the result of the % operator is the remainder. In both operations, if the value of the second operand is zero, the behavior is undefined.
When a finite value of real floating type is converted to an integer type other than _Bool, the fractional part is discarded (i.e., the value is truncated toward zero). If the value of the integral part cannot be represented by the integer type, the behavior is undefined.
no subject
Date: 2013-11-19 06:44 am (UTC)no subject
Date: 2013-11-19 06:50 am (UTC)no subject
Date: 2013-11-19 06:52 am (UTC)no subject
Date: 2013-11-19 06:56 am (UTC)no subject
Date: 2013-11-19 07:23 am (UTC)no subject
Date: 2013-11-19 07:26 am (UTC)no subject
Date: 2013-11-19 07:31 am (UTC)int i = -1;unsigned u;
printf("%d\n", (i%2)^(u%1));
потому что правила распространения беззнаковости по дереву выражения нечеткие.
no subject
Date: 2013-11-19 07:33 am (UTC)no subject
Date: 2013-11-19 06:52 am (UTC)А потом обновляешь компилятор или запускаешь другой компилятор на том же процессоре с той же ОС, и результат другой.
no subject
Date: 2013-11-19 06:57 am (UTC)no subject
Date: 2013-11-19 07:07 am (UTC)no subject
Date: 2013-11-19 07:27 am (UTC)