I have been working on using trigonometric functions in our code (In order to calculate distance from robot to vision tetra) and while it is able to calculate the value of tan(45) as 1, any other tan(x) value would be a decimal value, therefore i changed the variable that i had stored the value in to a float type, and told it to calculate some other tan(x) values (Just to make sure that the functions works). I have been getting as an answer some huge 5 digit numbers such as the one in the subject (Where ‘XXX’ is some 3 random numbers). Most of these numbers are somewhere near various powers of 2, such as 2^14, and 2^16. This has been happening with both Team 296 CORDIC Math library, and the math.h library that comes with the mcc18 compiler. Does anyone know what might be causing this?
I have had the exact same problem before. I am pretty sure the problem occurs when it tries to change the float to an int. If you aren’t doing that, make sure you are declaring the variable as an float when you printf() it. That fixed our problem anyway
Thanks for the reply, schenkin. Your reply prompted me to google the % specifiers used in ANSI C, and i figured out that i was using %d - signed integer, instead of %f - signed decimal.