magmalloy 0 Posted February 18, 2011 Report Share Posted February 18, 2011 (edited) Hi I'm trying to do some maths in BoostC whereby I multiply an integer variable by a fixed decimal number, and I need to get an integer value as the product somehow (I'm not bothered about losing a bit of accuracy with that). I've tried some code using methods from here but it doesn't work. It was along these lines: int result; int variable; (int) result = variable * 0.433; or result = (int) (variable *0.433); ... and many variations thereof. How can I do this with BoostC? I get the following error message: Error: Unresolved external function:'__div_16_16(unsigned short,unsigned short)' Error: Unresolved external function:'__div_16_16(unsigned short,unsigned short)' Error: Unresolved external function:'__div_16_16(unsigned short,unsigned short)' Error: Unresolved external function:'__div_16_16(unsigned short,unsigned short)' Error: Unresolved external function:'__div_16_16(unsigned short,unsigned short)' Error: Unresolved external function:'__div_16_16(unsigned short,unsigned short)' Error: Unresolved external function:'__div_16_16(unsigned short,unsigned short)' Error: Unresolved external function:'__div_16_16(unsigned short,unsigned short)' Error: Unresolved external function:'__div_16_16(unsigned short,unsigned short)' Error: Unresolved external function:'__div_16_16(unsigned short,unsigned short)' Error: Unresolved external function:'__div_16_16(unsigned short,unsigned short)' Error: Unresolved external symbol, function:__div_16_16 Edited February 18, 2011 by magmalloy Quote Link to post Share on other sites

Reynard 0 Posted February 18, 2011 Report Share Posted February 18, 2011 Floating point variables are not native data types in SB. Use the floating point library to do what you need. Cheers Reynard Quote Link to post Share on other sites

magmalloy 0 Posted February 18, 2011 Author Report Share Posted February 18, 2011 (edited) Use the floating point library to do what you need. So there is a way to do this? Phew ... Where could I find more information on the floating point library routines needed please? Edited February 18, 2011 by magmalloy Quote Link to post Share on other sites

Reynard 0 Posted February 18, 2011 Report Share Posted February 18, 2011 Use the Help menu from the IDE and there is the FP library manual. Cheers Reynard Quote Link to post Share on other sites

magmalloy 0 Posted February 21, 2011 Author Report Share Posted February 21, 2011 (edited) ***NVM I resolved it by adding the libc.pic16.lib file to the project. ( I'm still getting an error when I try to convert an integer value being read from the ADC module into a float variable so it can be multiplied by another float. *EDIT if I define the adc input as a float in the beginning of my code, I'm still unable to process the multiplication (*also if I use float32_from_int32). Is this because of the number of bits it uses? float adcin; float adcbuffer; adcin = adc_measure(1)>>3; adcbuffer = float32_mul( adcin, 1.432 ); Error: Unresolved external function:'float32_mul(float,float)' Error: Unresolved external function:'float32_mul(float,float)' Error: Unresolved external function:'float32_mul(float,float)' Error: Unresolved external function:'float32_mul(float,float)' Error: Unresolved external function:'float32_mul(float,float)' Error: Unresolved external function:'float32_mul(float,float)' Error: Unresolved external function:'float32_mul(float,float)' Error: Unresolved external function:'float32_mul(float,float)' Error: Unresolved external function:'float32_mul(float,float)' Error: Unresolved external function:'float32_mul(float,float)' Error: Unresolved external function:'float32_mul(float,float)' Error: Unresolved external symbol, function:float32_mul **EDIT if I add the float.pic16.lib library I get all these error messages for the same code (in fact these error messages seem to appear only because of the library for some reason?!? ): Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__mul_32u_32u Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__mul_32u_32u Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__mul_32u_32u Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__mul_32u_32u Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__mul_32u_32u Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__mul_32u_32u Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__mul_32u_32u Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__mul_32u_32u Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__mul_32u_32u Error: Unresolved external function:'__mul_32u_32u(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__mul_32u_32u Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__div_32_32 Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__div_32_32 Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__div_32_32 Error: Unresolved external function:'__div_32_32(unsigned long,unsigned long)' Error: Unresolved external symbol, function:__div_32_32 *RESOLVED) Edited February 21, 2011 by magmalloy Quote Link to post Share on other sites

AlexR 0 Posted February 21, 2011 Report Share Posted February 21, 2011 (edited) Rather than using floating point arithmetic which eats up PIC resources why not keep it all in integers. The following code works in simulation long int_result = 0; int final_result = 0; int variable; int_result = variable * 433; final_result = int_result/1000; In theory this should also work but for some reason when I step though it in debug mode I get a negative answer; Looks like it could be a bug! long int_result = 0; int variable; int_result = variable * 433/1000; Edited February 21, 2011 by AlexR Quote Link to post Share on other sites

Reynard 0 Posted February 21, 2011 Report Share Posted February 21, 2011 Hi Alex, You need to cast the variable to a long otherwise multiplying by 433 may exceed an integer size. int_result = (long)variable * 433/1000; Cheers Reynard Quote Link to post Share on other sites

AlexR 0 Posted February 21, 2011 Report Share Posted February 21, 2011 Thanks for that Renard, I did get my int's and long,s mixed up. As you point out casing "variable" to long fixes it up so the code should read: int result; int variable; result = (long)variable * 433/1000; Quote Link to post Share on other sites

Reynard 0 Posted February 21, 2011 Report Share Posted February 21, 2011 Don't forget to add the #include <float.h> header to your source. This seems to work: int adcValue = 100; long result; result = float32_to_int32(float32_mul(float32_from_int32((int32)adcValue), 0.433)); but like Alex says, it is a bit overkill if you do not have further use for FP numbers. Cheers Reynard Quote Link to post Share on other sites

## Recommended Posts

## Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.

Note:Your post will require moderator approval before it will be visible.