Windows中sqrt()函数的域错误未将errno设置为EDOM,在Linux上正确显示,但在Windows上失败(使用GCC 7.4)...
#include <stdio.h>
#include <errno.h>
#include <math.h>
int main () {
double val;
errno = 0;
val = sqrt(-10);
if(errno == EDOM) {
printf("Invalid value \n");
} else {
printf("Valid value\n");
}
errno = 0;
val = sqrt(10);
if(errno == EDOM) {
printf("Invalid value\n");
} else {
printf("Valid value\n");
}
return(0);
}
Run Code Online (Sandbox Code Playgroud)
预期结果:无效值有效值实际结果:有效值有效值