Can someone advise how to do rounding on float numbers?
I don't see a rounding function under the calculation Icons list of functions.
Ondra
float number rounding
Moderator: Benj
Re: float number rounding
When I tried the code below I got a compile error. I have attached my file, have a look.
Ondra
C:\Documents and Settings\Ondra\Desktop\Pebble 8_Dec24_09\Test programs\Sensor_distance calulator v4.c(495): error: can't convert 'int32' to 'float'
C:\Documents and Settings\Ondra\Desktop\Pebble 8_Dec24_09\Test programs\Sensor_distance calulator v4.c(495:22): error: failed to generate expression
Sensor_distance calulator v4.c success
failure
Return code = 1
Flowcode was unable to compile the flowchart's C code due to the following errors:
If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.
Ondra
C:\Documents and Settings\Ondra\Desktop\Pebble 8_Dec24_09\Test programs\Sensor_distance calulator v4.c(495): error: can't convert 'int32' to 'float'
C:\Documents and Settings\Ondra\Desktop\Pebble 8_Dec24_09\Test programs\Sensor_distance calulator v4.c(495:22): error: failed to generate expression
Sensor_distance calulator v4.c success
failure
Return code = 1
Flowcode was unable to compile the flowchart's C code due to the following errors:
If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.
- Attachments
-
- Sensor_distance calulator v4.fcf
- (12.75 KiB) Downloaded 270 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: float number rounding
Hello Ondra
This problem is related to the round function. For some reason this is not generating C code correctly so I will look into this for you.
As a workaround you can use C code for now which will allow you to compile. Unfortunatley it will no longer simulate the round function.
The C code for the round command in your program should look like this.
FCV_FLT_FOOT_INCHES = float32_round_to_int(FCV_FLTVAL);
Before you call the C command you can also specify the following in C.
float_rounding_mode = X;
where X =
float_round_nearest_even = 0
float_round_down = 1
float_round_up = 2
float_round_to_zero = 3
I have attached an updated version of your program that should compile correctly now.
This problem is related to the round function. For some reason this is not generating C code correctly so I will look into this for you.
As a workaround you can use C code for now which will allow you to compile. Unfortunatley it will no longer simulate the round function.
The C code for the round command in your program should look like this.
FCV_FLT_FOOT_INCHES = float32_round_to_int(FCV_FLTVAL);
Before you call the C command you can also specify the following in C.
float_rounding_mode = X;
where X =
float_round_nearest_even = 0
float_round_down = 1
float_round_up = 2
float_round_to_zero = 3
I have attached an updated version of your program that should compile correctly now.
- Attachments
-
- Sensor_distance calulator v4.fcf
- (14 KiB) Downloaded 291 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel