having only started with Teensy and C 3 to 4 weeks ago I am a noob. I also have no clue how to use this forum properly, so please bear with me.
When I am declaring some numbers either as float or double and then print them out, I get different results. I understand that a float will provide less precision than a double but curiously neither one of them matches the input after a number of digits.
#define ARM_MATH_CM4
#include <arm_math.h>
// Calibration parameter s
float CAL1_PARAM_A = 2.30877461071517E+05;
float CAL1_PARAM_B = -1.96685260458407E-01;
float CAL1_PARAM_C = -6.56726954265664E-06;
float CAL1_PARAM_D = 1.42999616118481E-11;
double CAL2_PARAM_A = 2.30877461071517E+05;
double CAL2_PARAM_B = -1.96685260458407E-01;
double CAL2_PARAM_C = -6.56726954265664E-06;
double CAL2_PARAM_D = 1.42999616118481E-11;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // Set up serial port.
delay(5000);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print(CAL1_PARAM_A * 1,7);
Serial.print("\t");
Serial.print(CAL1_PARAM_B * 1000000,7);
Serial.print("\t");
Serial.print(CAL1_PARAM_C * 10000000000,7);
Serial.print("\t");
Serial.print(CAL1_PARAM_D * 100000000,7);
Serial.println("\t");
Serial.print(CAL2_PARAM_A * 1,7);
Serial.print("\t");
Serial.print(CAL2_PARAM_B * 1000000,7);
Serial.print("\t");
Serial.print(CAL2_PARAM_C * 10000000000,7);
Serial.print("\t");
Serial.print(CAL2_PARAM_D * 100000000,7);
Serial.println("\t");
Serial.println();
delay(1000);
}
and here is the display
When I am declaring some numbers either as float or double and then print them out, I get different results. I understand that a float will provide less precision than a double but curiously neither one of them matches the input after a number of digits.
#define ARM_MATH_CM4
#include <arm_math.h>
// Calibration parameter s
float CAL1_PARAM_A = 2.30877461071517E+05;
float CAL1_PARAM_B = -1.96685260458407E-01;
float CAL1_PARAM_C = -6.56726954265664E-06;
float CAL1_PARAM_D = 1.42999616118481E-11;
double CAL2_PARAM_A = 2.30877461071517E+05;
double CAL2_PARAM_B = -1.96685260458407E-01;
double CAL2_PARAM_C = -6.56726954265664E-06;
double CAL2_PARAM_D = 1.42999616118481E-11;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // Set up serial port.
delay(5000);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print(CAL1_PARAM_A * 1,7);
Serial.print("\t");
Serial.print(CAL1_PARAM_B * 1000000,7);
Serial.print("\t");
Serial.print(CAL1_PARAM_C * 10000000000,7);
Serial.print("\t");
Serial.print(CAL1_PARAM_D * 100000000,7);
Serial.println("\t");
Serial.print(CAL2_PARAM_A * 1,7);
Serial.print("\t");
Serial.print(CAL2_PARAM_B * 1000000,7);
Serial.print("\t");
Serial.print(CAL2_PARAM_C * 10000000000,7);
Serial.print("\t");
Serial.print(CAL2_PARAM_D * 100000000,7);
Serial.println("\t");
Serial.println();
delay(1000);
}
and here is the display