Truncated match.
PICList
Thread
'Does this Float your Boat?'
1999\08\20@135121
by
Lawrence Lile
I'm trying to use floating point numbers in CCS C compiler. The manual
doesn't cover this very thoroughly: Even the explanation of floating point
number format is pretty cryptic  I could not decode it even with examples
from the book.
1. What is the valid range for floating point numbers in CCS C? What is
the highest positive, lowest negative and smallest number that can be
represented?
2. Say float y = 12 and long x = 12. Now SQRT(x) is going to be
truncated to 3, and x squared is 9. So much for root mean square being
very accurate using longs. What about floats? What happens if you take
SQRT(y) and then calculate y squared? What will it's value be?
3. What are the rules for assigning bytes and longs to floats?
int x;
long y;
float z;
x=z;
y=z;
What are the results?
1999\08\20@141237
by
Harold Hallikainen

While not answering your questions... I had a couple comments...
On Fri, 20 Aug 1999 12:49:44 0500 Lawrence Lile <spam_OUTlilelTakeThisOuTTOASTMASTER.COM>
writes:
>2. Say float y = 12 and long x = 12. Now SQRT(x) is going to be
>truncated to 3, and x squared is 9. So much for root mean square
>being
>very accurate using longs. What about floats? What happens if you
>take
>SQRT(y) and then calculate y squared? What will it's value be?
>
I did RMS conversions by taking 8 bit samples, squaring them, and
adding the result to a 24 bit total. After I had accumulated 256
samples, the 24 bit total was divided by 256 (the lower 8 bits discarded)
giving the average or mean of the squares (is this starting to look like
COBOL?) and the square root of the remaining 16 bit average was then
taken, resulting in an 8 bit RMS. All done in assembly...
Harold
Harold Hallikainen
.....haroldKILLspam@spam@hallikainen.com
Hallikainen & Friends, Inc.
See the FCC Rules at http://hallikainen.com/FccRules and comments filed
in LPFM proceeding at http://hallikainen.com/lpfm
___________________________________________________________________
Get the Internet just the way you want it.
Free software, free email, and free Internet access for a month!
Try Juno Web: dl.http://www.juno.com/dynoget/tagj.
1999\08\20@142309
by
Erik Reikes

>2. Say float y = 12 and long x = 12. Now SQRT(x) is going to be
>truncated to 3, and x squared is 9. So much for root mean square being
>very accurate using longs. What about floats? What happens if you take
>SQRT(y) and then calculate y squared? What will it's value be?
>
Try prescaling everything by 100 (or other squares of ten)... i.e. do your
calculations in "hundredths".
so 12^.5 = 3 as an int, but 1200^.5 is 34, and 34^2 is 1156. 120000 ^.5 is
346... The last step is scaling back by the square root of your scale
factor, or depending on the way you set up your system leaving everything
as is. For square roots the scaling factor must be a square of 10 (or a
square of whatever base you are using).
>
>3. What are the rules for assigning bytes and longs to floats?
>
>int x;
>long y;
>float z;
>x=z;
>y=z;
Best to avoid assigning floats to any kind of int. I believe spec is to
truncate, 5.0 = 5.567 = 5.999 = 5.
Best way to find out is to try it tho.... YMMV
E
More... (looser matching)
 Last day of these posts
 In 1999
, 2000 only
 Today
 New search...