Whats the difference and what should I use

Hello, whats the difference between float(atan(14.865f)) and atanf(14.865f)
and what should I use?
In C++ (if you #include <cmath> and use std::atan (or using namespace std), They are exact same thing. You should skip the redundant cast and use std::atan(14.865f)

If you're using the C math library (from #include <math.h> ), atan returns a double, which is then cast to float, and the result may, in principle, depend on the currently installed floating-point rounding mode.

example:
1
2
3
4
5
6
7
8
9
10
11
12
#include <math.h>
#include <fenv.h>
#include <iostream>
#include <iomanip>

int main()
{
    fesetround(FE_UPWARD);
    std::cout << std::setprecision(100)
              << float(atan(14.865f)) << '\n'
              << atanf(14.865f) << '\n';
}
1.503625392913818359375
1.50362551212310791015625


online demo: http://coliru.stacked-crooked.com/a/3c7d79c2dc840063
Last edited on
Thank you!
Topic archived. No new replies allowed.