Searching \ for '[OT] Fractional binary vs fixed point or scaled in' in subject line. () Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=fractional+binary
Search entire site for: 'Fractional binary vs fixed point or scaled in'.

Exact match. Not showing close matches.
'[OT] Fractional binary vs fixed point or scaled in'
1998\12\15@230805 by  I'm confused.

I never use fractional binary.  I've always used fixed point binary,
known as scaled integer and manipulated accordingly.  It's the FORTH
way.  Chapter 5 of Leo Brodie's "Starting FORTH" covers "The Philosophy
of integer arithmetic."  A fascinating introduction as to why floating
point is rarely needed.

Do the people who use fractional binary have some reason that outweighs
the scaled integer option?  Is there some feature of the PIC instruction
set that lends itself to fractional binary over scaled integer?

Background: fractional binary is the use of two binary strings, one
representing the left of the decimal place and the other the right.
Scaled integer representation is use of a single binary string but
treating the value as scaled by some factor.  Scaling by powers of ten
eases display in decimal characters; just insert the decimal point in
the same place each time.  Scaling by powers of two eases further
calculations, because they become shifts.

Floating point is an enhancment of scaled integer, in that another
field, the exponent, holds the current scaling factor in binary.

--
James Cameron                                      (cameron stl.dec.com)

OpenVMS, Linux, Firewalls, Software Engineering, CGI, HTTP, X, C, FORTH,
COBOL, BASIC, DCL, csh, bash, ksh, sh, Electronics, Microcontrollers,
Disability Engineering, Netrek, Bicycles, Pedant, Farming, Home Control,
Remote Area Power, Greek Scholar, Tenor Vocalist, Church Sound, Husband.

"Specialisation is for insects." -- Robert Heinlein.  James Cameron wrote:

> I'm confused. I never use fractional binary.  I've always used fixed point
> binary, known as scaled integer and manipulated accordingly. It's the FORTH
> way. Chapter 5 of Leo Brodie's "Starting FORTH" covers "The Philosophy of
> integer arithmetic."  A fascinating introduction as to why floating point
> is rarely needed. Do the people who use fractional binary have some reason
> that outweighs the scaled integer option? Is there some feature of the PIC
> instruction set that lends itself to fractional binary over scaled integer?

Probably all misunderstooding here are appear due to my level of english
;(
I mean right part of integer (after dot) is fractional part with powers
of
1/2 1/4 1/8 etc... while left part of integer (before dot) is int with
power
of 1 2 3 8 etc..

> Background: fractional binary is the use of two binary strings, one repre-
> senting the left of the decimal place and the other the right. Scaled integer
> representation is use of a single binary string but treating the value as
> scaled by some factor.  Scaling by powers of ten eases display in decimal
> characters; just insert the decimal point in the same place each time. Scaling
> by powers of two eases further calculations, because they become shifts.

Is it real remainder in second register or something else? The links in
net with information about fractional and others theories in english
will
be very useful.

integer
and ways of simple convertation it to decimal view.

> Floating point is an enhancment of scaled integer, in that another
> field, the exponent, holds the current scaling factor in binary.

The are also another arithmetical base which I learned about sometime
ago
while studing in university - arithmetic is based on non-carry very easy
addition/substraction, easy multiplication but very hard division. It
based
on simple numbers.

WBR Dmitry.  Dmitry Kiryashov wrote:
> arithmetic?
> Is it real remainder in second register or something else? The links in
> net with information about fractional and others theories in english
> will be very useful.

Okay, I'm not sure I understand what you are asking, but I will take a
guess that you want to know more about how to use scaled integer, and
you would like to see web pointers to such information as well.

Unfortunately, I don't have any web pointers to this information,
because I learned it from a book.

Do you know C?  Here is a simple example of a scaled integer variable;
which since the C language doesn't know about has to be expressed as a
non-scaled integer and treated accordingly.

{
int counter;        /* scaled integer counter               */
int scale = 10;     /* constant scale factor, 1024, 10 bits */

/* reset the counter */
counter = 0;

counter = ( 868 << scale );

/* increment the counter by one */
counter += ( 1 << scale );

/* increment the counter by 0.5 */
counter += 512;

/* display the counter as whole units in decimal */
printf ( "%d\n", counter >> 10 );

/* add some arbitrary number to the counter */
counter = counter + ( arbitrary << 10 );
}

The thing to remember with scaled integer is that it helps you avoid
difficult multiplications or divisions.  Most operations involve
arithmetic shifts.

I recommend reading the book Starting FORTH by Leo Brodie for more
background.  Try a library?

--
James Cameron                                      (cameron stl.dec.com)

OpenVMS, Linux, Firewalls, Software Engineering, CGI, HTTP, X, C, FORTH,
COBOL, BASIC, DCL, csh, bash, ksh, sh, Electronics, Microcontrollers,
Disability Engineering, Netrek, Bicycles, Pedant, Farming, Home Control,
Remote Area Power, Greek Scholar, Tenor Vocalist, Church Sound, Husband.

"Specialisation is for insects." -- Robert Heinlein.  James Cameron wrote:

>     /* display the counter as whole units in decimal */
>     printf ( "%d\n", counter >> 10 );

> The thing to remember with scaled integer is that it helps you avoid
> difficult multiplications or divisions.  Most operations involve
> arithmetic shifts.

I mean the scaled integers too but I write program mainly in asm not C
;-)

The right 10 bits in your example is exactly what I mean a fractional
part.
To quickly convert it to decimal view some thinking is required. The
tage of C is that compiler hide the type convertation from programmer.
The
disadvantage is largest data and program memory demanding.

When I have enought of memory I'm also write in C. ;-)

WBR Dmitry.  |I never use fractional binary.  I've always used fixed point binary,
|known as scaled integer and manipulated accordingly....

|Do the people who use fractional binary have some reason that outweighs
|the scaled integer option?  Is there some feature of the PIC instruction
|set that lends itself to fractional binary over scaled integer?

Fractional binary is simply a special case of fixed-point or
scaled-integer binary in which the unity point is located between
to machine words of the number; e.g. an 8+8 bit fractional binary
number is the same as a 16-bit number scaled by a factor of 256.
Since scaling by 256 (or 65536) is easy, fractional binary can be
quite handy.

Note also that conversion of a fractional binary number to decimal
is somewhat easier than the general case of binary-to-decimal conv-
ersion since it requires multiplication by 10 rather than division.

Finally, FYI, the Motorola 68HC11 actually does have an instruction
for fractional division.

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