Relative Content

Tag Archive for c++floating-point

Why does carg(-0) return -pi?

I noticed that when working with double complex numbers in C, when a real number with a negative 0 imaginary part is passed to carg()M_PI is returned rather than 0 or M_PI. Why is that? I found this out because another function that used carg() returned the wrong sign for the imaginary part (the function that gets broken by this behavior of carg() is newlibs cpow).

Why does carg(-0) return -pi?

I noticed that when working with double complex numbers in C, when a real number with a negative 0 imaginary part is passed to carg()M_PI is returned rather than 0 or M_PI. Why is that? I found this out because another function that used carg() returned the wrong sign for the imaginary part (the function that gets broken by this behavior of carg() is newlibs cpow).

Why does carg(-0) return -pi?

I noticed that when working with double complex numbers in C, when a real number with a negative 0 imaginary part is passed to carg()M_PI is returned rather than 0 or M_PI. Why is that? I found this out because another function that used carg() returned the wrong sign for the imaginary part (the function that gets broken by this behavior of carg() is newlibs cpow).

Weird math error using floating point arithmetic in C

I’m trying to extract the first digit of an interger. For that I take the number, divide it by 10, and then substract the interger part of that number, resulting in only the decimal part, wich is then multiplied by 10, and voila, the first digit of the interger.