aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hansen2011-01-20 01:27:54 +0100
committerNicolas Schodet2011-01-21 23:15:36 +0100
commitd6bd4ec76414e535a297e37aef9de066c20b7e10 (patch)
treefb9ec04067a061d51526f26e419f9332849f59dc
parent297e078de44336eb37e59c31638988de4adfb88b (diff)
use float instead of double when possible
Useless use of double precision math will include large functions and eat CPU time. Imported from NXT Enhanced Firmware.
-rw-r--r--AT91SAM7S256/Source/Functions.inl30
-rw-r--r--AT91SAM7S256/Source/c_cmd.c22
-rw-r--r--AT91SAM7S256/Source/c_ui.h2
3 files changed, 27 insertions, 27 deletions
diff --git a/AT91SAM7S256/Source/Functions.inl b/AT91SAM7S256/Source/Functions.inl
index 4211137..fb35f9a 100644
--- a/AT91SAM7S256/Source/Functions.inl
+++ b/AT91SAM7S256/Source/Functions.inl
@@ -83,19 +83,19 @@ const UBYTE SENSORFORMAT[SENSORS][9] =
const float SENSORDIVIDER[SENSORS] =
{
- 1.0, // MENU_SENSOR_EMPTY
- 1.0, // MENU_SENSOR_SOUND_DB
- 1.0, // MENU_SENSOR_SOUND_DBA
- 1.0, // MENU_SENSOR_LIGHT
- 1.0, // MENU_SENSOR_LIGHT_AMB
- 1.0, // MENU_SENSOR_TOUCH
- 1.0, // MENU_SENSOR_MOTOR_DEG
- 360.0, // MENU_SENSOR_MOTOR_ROT
- 2.54, // MENU_SENSOR_ULTRASONIC_IN
- 1.0, // MENU_SENSOR_ULTRASONIC_CM
- 10.0, // MENU_SENSOR_IIC_TEMP_C
- 10.0, // MENU_SENSOR_IIC_TEMP_F
- 1.0 // MENU_SENSOR_COLOR
+ 1.0f, // MENU_SENSOR_EMPTY
+ 1.0f, // MENU_SENSOR_SOUND_DB
+ 1.0f, // MENU_SENSOR_SOUND_DBA
+ 1.0f, // MENU_SENSOR_LIGHT
+ 1.0f, // MENU_SENSOR_LIGHT_AMB
+ 1.0f, // MENU_SENSOR_TOUCH
+ 1.0f, // MENU_SENSOR_MOTOR_DEG
+ 360.0f, // MENU_SENSOR_MOTOR_ROT
+ 2.54f, // MENU_SENSOR_ULTRASONIC_IN
+ 1.0f, // MENU_SENSOR_ULTRASONIC_CM
+ 10.0f, // MENU_SENSOR_IIC_TEMP_C
+ 10.0f, // MENU_SENSOR_IIC_TEMP_F
+ 1.0f // MENU_SENSOR_COLOR
};
@@ -322,11 +322,11 @@ void cUiUpdateSensor(SWORD Time)
{
if (Sensor == MENU_SENSOR_IIC_TEMP_F)
{
- VarsUi.DatalogSampleValue[Port - MENU_PORT_1] = (SLONG)((float)(Tmp + 4544) / 14.2);
+ VarsUi.DatalogSampleValue[Port - MENU_PORT_1] = (SLONG)((float)(Tmp + 4544) / 14.2f);
}
else
{
- VarsUi.DatalogSampleValue[Port - MENU_PORT_1] = (SLONG)((float)Tmp / 25.6);
+ VarsUi.DatalogSampleValue[Port - MENU_PORT_1] = (SLONG)((float)Tmp / 25.6f);
}
VarsUi.DatalogSampleValid[Port - MENU_PORT_1] = TRUE;
}
diff --git a/AT91SAM7S256/Source/c_cmd.c b/AT91SAM7S256/Source/c_cmd.c
index 7483846..fc74b3a 100644
--- a/AT91SAM7S256/Source/c_cmd.c
+++ b/AT91SAM7S256/Source/c_cmd.c
@@ -3436,11 +3436,11 @@ ULONG cCmdGetSByte(void * pVal) {
ULONG cCmdGetFloat(void * pVal) {
float tempVal = *(float*)pVal;
- if (tempVal >= 0) {
- tempVal += 0.5;
+ if (tempVal >= 0.0f) {
+ tempVal += 0.5f;
}
else {
- tempVal -= 0.5;
+ tempVal -= 0.5f;
}
return (ULONG)tempVal;
}
@@ -4613,7 +4613,7 @@ NXT_STATUS cCmdInterpUnop2(CODE_WORD * const pCode)
pArg2 = cCmdResolveDataArg(Arg2, 0, NULL);
FltArgVal2 = cCmdGetValFlt(pArg2, TypeCode2);
// is number too big for display? then format differently and don't bother with trailing zeros
- if ((FltArgVal2 > 9999999999999.99)||(FltArgVal2 < -999999999999.99)){ // these are the widest %.2f numbers that will fit on display
+ if ((FltArgVal2 > 9999999999999.99f)||(FltArgVal2 < -999999999999.99f)){ // these are the widest %.2f numbers that will fit on display
strcpy (FormatString, "%.6g");
}
else{
@@ -4951,20 +4951,20 @@ float cCmdUnop2Flt(CODE_WORD const Code, float Operand, TYPE_CODE TypeCode)
else if(opCode == OP_ABS)
return fabsf(Operand);
else if(opCode == OP_SQRT)
- return sqrt(Operand);
+ return sqrtf(Operand);
#if 0
else if(opCode == OP_SIN)
- return sin(Operand);
+ return sinf(Operand);
else if(opCode == OP_COS)
- return cos(Operand);
+ return cosf(Operand);
else if(opCode == OP_TAN)
- return tan(Operand);
+ return tanf(Operand);
else if(opCode == OP_ASIN)
- return asin(Operand);
+ return asinf(Operand);
else if(opCode == OP_ACOS)
- return acos(Operand);
+ return acosf(Operand);
else if(opCode == OP_ATAN)
- return atan(Operand);
+ return atanf(Operand);
#endif
else
{
diff --git a/AT91SAM7S256/Source/c_ui.h b/AT91SAM7S256/Source/c_ui.h
index e74dcbe..e0f8f4a 100644
--- a/AT91SAM7S256/Source/c_ui.h
+++ b/AT91SAM7S256/Source/c_ui.h
@@ -36,7 +36,7 @@
#define CHECKBYTE 0x78 // Used to validate NVData
-#define BATTERY_COUNT_TO_MV 13.848 // Battery count to mV factor [mV/cnt]
+#define BATTERY_COUNT_TO_MV 13.848f // Battery count to mV factor [mV/cnt]
#define LOW_BATT_THRESHOLD 6 // Low batt conunts before warning
#define BUTTON_DELAY_TIME 800 // Delay before first repeat [mS]