Comparing Fortran & C++ assembler for int = floor(sqrt(…))
37
6
I have implemented a function in Fortran and C++ each: #include <math.h> void dbl_sqrt_c(double *x, double *y){ *y = sqrt(*x - 1.0); return; } pure subroutine my_dbl_sqrt(x,y) bind(c, name="dbl_sqrt_fort") USE, INTRINSIC :: ISO_C_BINDING implicit none real(kind=c_double), intent(in) :: x real(kind=c_double), intent(out) :: y y = sqrt(x - 1d0) end subroutine my_dbl_sqrt I compared them in the compiler explorer: Fortran: https://godbolt.org/z/froz4rx97 C++: https://godbolt.org/z/45aex99Yz And the way I read the assembler, they do basically the same thing, but C++ checks whether the argument of the sqrt is negative, which Fortran doesn't. I compared their performance using googles benchmark, but they are pretty evenly...