## float2int

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

billduck
Posts: 140
Joined: Thu Jul 01, 2010 1:57 am
Contact:

### float2int

I have a question about a compile error. In a large program, I am passing a couple of floats to a macro. In the macro, I define an integer data type, and convert the float to an integer. When I compile, I get the error " undefined reference to float32_to_int32' ". I wrote a short program, main and 1 macro, and it will simulate, but has the same error message. Any suggestions?
Attachments
MOD.fcf_avr
The float2int conversion is located in the macro "MoveEL".

Sean
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Contact:

### Re: float2int

I will look into the function naming problem.

As a workaround. It is possible that the two functions to convert, in either direction, between floats and ints are not required in Flowcode for AVR. Their main purpose is to allow import/export compatibility with Flowcode for PIC. The compiler seems to be capable of automatically converting between the basic numeric data types - if the values are valid:

float_var = int_var
int_var = float_var

If you want to use the float_to_int function, putting the following line in the supplementary code section of the program (view -> Project Options -> Supplementary Code) prevents the compiler error:

#define float32_to_int32 float32_to_int

billduck
Posts: 140
Joined: Thu Jul 01, 2010 1:57 am
Contact:

### Re: float2int

Thanks, That worked for compiling.
I added another operation - square root of the sum of the squares, and the error is, when compiling, " undefined reference to float32_sqrt' ". Is there is similar fix to make that compile?
I uploaded the modified Flowcode example.
Attachments
MOD.fcf_avr

Sean
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Contact:

### Re: float2int

Hello,

I have attached a new 'internals.h' file that should correct the name problems identified with 3 floating point function calls:

float to int
int to float
sqrt
internals.h
The file should be copied into the FCD folder of the Flowcode AVR V4 installation (overwriting the original).

billduck
Posts: 140
Joined: Thu Jul 01, 2010 1:57 am
Contact:

### Re: float2int

Thanks So much. My project could not move forward without your help.

petesmart
Valued Contributor
Posts: 395
Joined: Thu May 06, 2010 11:42 am
Location: Sydney, Australia
Contact:

### Re: float2int

Hi Sean,

I have had similar issues on FC PIC V4.3... is there a fix for this available?

best regrds

Pete

Benj
Matrix Staff
Posts: 14848
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

### Re: float2int

Hi Pete,

Are you having the problem with PIC or dsPIC? If its with PIC then have you tried upgrading to v4.5 and seeing if the problems still exists?

petesmart
Valued Contributor
Posts: 395
Joined: Thu May 06, 2010 11:42 am
Location: Sydney, Australia
Contact:

### Re: float2int

Hi Ben,

Its on PIC version... I will give v4.5 a go and come back to you...

Thanks

Pete

petesmart
Valued Contributor
Posts: 395
Joined: Thu May 06, 2010 11:42 am
Location: Sydney, Australia
Contact:

### Re: Int2float

Hi Ben,

Attempting to convert an integer to floating point number and get the following error on both ARM and dsPic versions... software I belive is the latest version Flowcode PIC24&dsPIC v4.4.13.69. Have not had a chance to verify on FC PIC v4.5

Created a small test file to demo the problem

Comes up with these errors on compile

int 2 float test 1.c: In function 'main':

int 2 float test 1.c:81: warning: implicit declaration of function 'float32_from_int32'

then this one on assemby

int 2 float test 1.o(.text+0x618):O:\matrixmultimedia\test files\inclinometer\inclinometer v2\int 2 float test 1.c: undefined reference to float32_from_int32'

Error returned from [pic30-gcc.exe]

Return code = 1

Flowcode was unable to assemble the ASM file due to the following errors
:

test Files attached

I am suspecting a library problem.....Appreciate your help..

Thanks

Pete
Attachments
int 2 float test 1.msg.txt
int 2 float test 1.fcf_pic16

Benj
Matrix Staff
Posts: 14848
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

### Re: float2int

Hello Pete,

You could add this line of code to the supplementary code window to resolve the problem.

Code: Select all

#define float32_from_int32(a)   ((float)(a))`
Let me know how you get on.

petesmart
Valued Contributor
Posts: 395
Joined: Thu May 06, 2010 11:42 am
Location: Sydney, Australia
Contact:

### Re: float2int

Hi Ben,

Ok, that little piece of black magic worked on both ARM and dsPic ver of FC ...and I just realised i'm probably in the wrong forum space...my apologies.

Can you assist with some further

0) is this a bug, or something that I should have known? ( I am still remembering what I've forgotten in this space)

1) Can you explain why the definition is required in both Arm and dsPIC, FC PIC seemed to be ok?

2) I take it that the (a) is the variable to be processed by the function.. do i have to do this for every variable that I use with this function?

3) and... what about the other functions, such as float2int?

thanks again for the prompt response.. much apprecaited

best regards

Pete

Benj
Matrix Staff
Posts: 14848
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

### Re: float2int

Hello Pete,

0) This is a bug and is due to the fact we got the name of one or two of the float conversion functions a bit wrong. This has now been fixed for future revisions.

1) FC PIC has the float functions built into the compiler. AVR, ARM and dsPIC do not have the functions and do not need to use them however we have added them in for full compatibility with PIC programs so imports etc work correctly.

2) 'a' is a substitution for the definition's parameter and is merely a pre-processor symbol. i.e. you do not need to redefine using other letters.

3) I think most of the functions are fine however If you find another that will not compile then let me know.

petesmart
Valued Contributor
Posts: 395
Joined: Thu May 06, 2010 11:42 am
Location: Sydney, Australia
Contact:

### Re: float2int

Thanks Ben,

0) when you were referring to future revisions, am I up to date with both ARM and dsPIC? I did check via the FC application for updates and it did respond with no updates available?

1) am I correct in undersatnding that ARM and dsPIC you can simply make float equal integer or integer equal float without using the int2float or float2int function?

Thanks again for your prompt follow-up,

all the best,

Pete

Benj
Matrix Staff
Posts: 14848
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

### Re: float2int

Hello Pete,

0) Yes if the Flowcode portal page is saying you are up to date then there is currently no updates available for that version of Flowcode. I always ensure to keep the portal page up to date as updates are released.

1) Yes thats right, the functions are not required for ARM, AVR or dsPIC. In fact they are only required by the BoostC compiler. The HiTech compiler for PICs can also be used without the functions.