Originally posted by tuxd3v
View Post
I update your program ( if you write directly 1/0, may be gcc translate this directly in 'inf').
Code:
#include <stdio.h> void idiv(int a, int b) { printf("int %d / %d =", a, b); fflush(stdout); int d = a / b; printf("%d\n", d); fflush(stdout); } void fdiv(float a, float b) { printf("float %f / %f =", a, b); fflush(stdout); float d = a / b; printf("%f\n", d); fflush(stdout); } int main( int argc, char** argv ) { fdiv(1, 0); fdiv(-1, 0); fdiv(0, 0); idiv(1, 0); idiv(-1, 0); idiv(0, 0); return 0; }
Code:
# x86_64 float 1.000000 / 0.000000 =inf float -1.000000 / 0.000000 =-inf float 0.000000 / 0.000000 =-nan int 1 / 0 =Floating point exception (core dumped)
Code:
# risc-v float 1.000000 / 0.000000 =inf float -1.000000 / 0.000000 =-inf float 0.000000 / 0.000000 =nan int 1 / 0 =-1 int -1 / 0 =-1 int 0 / 0 =-1
So it seems that neither x86_64 nor risc-v trap in case of division by zero if the operation is between floating number. Different in case of integer number..
Comment