Searching \ for 'float - is it necessary? (was Re: Other MicroContr' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=other+microcontr
Search entire site for: 'float - is it necessary? (was Re: Other MicroContr'.

Truncated match.
PICList Thread
'float - is it necessary? (was Re: Other MicroContr'
1997\03\20@191100 by Steve Hardy

flavicon
face
> From: Walter Banks <spam_OUTwalterTakeThisOuTspamBYTECRAFT.COM>
> Werner Terreblanche wrote:
> >
> > To put this to a test, try finding a PIC C compilers that can do
> > floating point arithmetic.
>
> This is an unusual test for a C compiler. I have seen very few
> applications that would use a Microchip PIC class of processor
> where floating point support is a requirement.

I have to agree with Walter.  What would be much, much more useful
for a PIC compiler would be the ability to specify various fixed
point formats and the compiler then takes care of optimum scaling
of intermediate results.  If using C, then perhaps the following
syntax...

typedef fixed 8:3 unsigned int foo;
typedef fixed 15:15 signed int bar;

foo A;
bar B;

foo X;
bar Y;

X = A * B;      /* Throwing away sign of B */
Y = A + B;      /* Result truncation */
Y = B * B;      /* OK */



'fixed n:m' is a type qualifier (somewhat similar to 'long' or the
abominable 8086 pointer qualifiers) where n is the number of significant
bits, and m is the number of those bits after the implied binary point.
Thus a foo type represents a number between 0 and 7 7/8 and bar
represents -1 to +32767/32768, if using 2's complement.  Now if
a foo is multiplied by a bar, then the compiler will realise that
the result will have 8 significant bits (the smaller of the operands)
and 3 of those bits will be fractional.  However the result is unsigned type
so the compiler will warn about loss of sign.  If the code assigns the
result to a value with a smaller number of significant bits, or
a badly positioned binary point, then a warning will be issued in
which the compiler tells the user that significance loss or truncation
is occuring, and suggests a more appropriate type.

This leaves most of the thinking about the problem to the user,
with the compiler implementing the arithmetic in the most efficient
way and warning the user if something doesn't make sense.

Naturally, up to 32-bit precision should be supported.  (Then I
could implement my julian day calendar!)

This shouldn't be too hard for the compiler gurus to implement,
should it?

Regards,
SJH
Canberra, Australia

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...