Jump to content

Data Type Conversion Not Working


Recommended Posts

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 by magmalloy
Link to post
Share on other sites

***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 by magmalloy
Link to post
Share on other sites

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 by AlexR
Link to post
Share on other sites

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

Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...