Page 1 of 1

Can't compile/download square root function

Posted: Sun Feb 19, 2012 7:56 pm
by Odox00
Hi
I put a square root function into a calculation of float point numbers. It works in simulation mode but it fails when I try to compile and download it.
I can read those lines.

sqrt_fail.o: In function `main':
sqrt_fail.c:(.text+0x9f0): undefined reference to `float32_sqrt'


I use Flowcode ARM v.4.3.8.64 and ECRM40.

Re: Can't compile/download square root function

Posted: Sun Feb 19, 2012 11:07 pm
by Odox00
I also can't compile the MOD (modulo) function.

Re: Can't compile/download square root function

Posted: Mon Feb 20, 2012 11:10 am
by Benj
Hello,

If you click View -> Project Options, then tick Use Supplementary Code, then click the Supplementary code button and paste the following line of code into the top window then the square root function should compile correctly.

#define float32_sqrt sqrt

The MOD function is working ok for me.

test2 = test2 MOD 5

Re: Can't compile/download square root function

Posted: Wed Feb 22, 2012 10:56 pm
by Odox00
Thanks Benj.

Regarding the MOD function. I found out that I can compile if I use INT-variables, but not with FLOAT.

If I try compile <b = (v+360) MOD 360>, (v and b are FLOAT-variables) I get this:
Launching the compiler...
C:\Program Files\Matrix Multimedia\Flowcode ARM V4\Tools\MX_bats\arm7comp.bat "test" "D:\Flowcode"
In file included from test.c:37:
C:/PROGRA~1/MATRIX~1/FLOWCO~2/Tools/MX_bats/../Global/OSstubs.c:192: warning: 'struct tms' declared inside parameter list
C:/PROGRA~1/MATRIX~1/FLOWCO~2/Tools/MX_bats/../Global/OSstubs.c:192: warning: its scope is only this definition or declaration, which is probably not what you want
test.c: In function 'main':
test.c:510: error: invalid operands to binary %
test.c:516: warning: passing argument 3 of 'FCI_FLOAT_TO_STRING' discards qualifiers from pointer target type
test.c:521: warning: passing argument 1 of 'FCD_LCDDisplay0_PrintString' discards qualifiers from pointer target type
test.c:489: warning: return type of 'main' is not 'int'

Error returned from [arm-elf-gcc.exe]

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.

FINISHED
And as I said, it works in simulation.

Re: Can't compile/download square root function

Posted: Wed Feb 22, 2012 11:57 pm
by JonnyW
Hello. Flowcode v4 will let these things through in simulation. However, MOD (%) is illegal in all C compilers for floating point numbers as it only has meaning for integral values, and you must use the functions to convert to integers before performing the mod, or use the flt_rem() function:

Code: Select all

result = flt_rem(dividend, divisor)
(Note I'm only assuming this function exists in v4, I'm using v5 to test this, so sorry if it doesn't!)

Jonny

Re: Can't compile/download square root function

Posted: Fri Feb 24, 2012 12:28 am
by Odox00
I just found that there is a separate FLOAT function for using modulo with Float numbers.
fmod( x , y ) - floating point modulus (remainder of x divided by y)
Problem solved.