Jump to content

Boostc Bug - 16bit Vars?

Recommended Posts

The following code works perfectly in C2C Plus but has appears to have computational errors in boostc


make a loop that increments a short by 1 and feed it into this function. Somewhere in the upper range of 16bit vars the resultant goes crazy jumping all over the place. I plotted the output using a DAC onto an oscilloscope to graph it - I dunno how you will get the output... (btw the dac code has been checked vs a looping 0-255 and works flawlessly). I have not bothered to look deeper into how or why this is happening as I am on a deadline and c2c plus compiles this into working code. I hope this helps and I haven't simply done something wrong.


btw - feel free to use this code if you find it useful - the Babylonians liked it thousands of years ago :-)




char sqrt(short var_in)


// Babylonian approximation square root algorithm

// Note: Not optimized. Also, answer is truncated (no decimal section - 16bits!)


short guess = 128;

short gTemp;


for (loop = 0; loop < 5; loop++) // run for 5 itterations (more than close enough)


//guess = ((var_in / guess) + guess) / 2;

gTemp = var_in / guess;

gTemp = gTemp + guess;

gTemp = gTemp / 2;

guess = gTemp;


return guess;


Link to post
Share on other sites



Your code does not compile as it is (loop declaration missing).


But for me the results look quite correct.

I only check all results when compiled under BoostC and only a few under C2C-plus. I ran the code under the SourceBoost simulator.


Please sepecifiy values that don't give you what you don't expect

The results all seemed as I expected them.


I would suggest another problem exists.


BTW: I like the Babylonian agorithm :)




Link to post
Share on other sites
  • 4 months later...



I figured out what was wrong with this code (recently purchased BoostC and was forced to correct this problem...)


I declared my variables as short and they SHOULD have been declared as unsigned short.


If you wish to see the OLD code fail, calculate sqrt(34000) or some other high value. The var_in becomes NEGATIVE and messes up the works. defining everything as unsigned short solves the problem.


All is well with my world - thanks to all of the forum junkies for the help they gave me without knowing it as I read their words of wisdom.



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.

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.

  • Create New...