_Sub string match.
PICList
Thread
'Need a Floating Pint wizard (AN526 arrgh!!)'
1997\05\11@124531
by
erik
|
I have to use floating point maths in my application and am having a
problem with implementing it.
I'm trying to use the material in AN526. I have assembled and used the
demo program FLOAT.ASM under MPSIM. I've also used the demo "calculator"
FPREP.EXE which I got off the bulletin board.
The problem is that FLOAT.ASM and FPREP.EXE use completely different
representations for floating point numbers.
I can understand the format used by FPREP.EXE, but what I need to understand
is the format used by FLOAT.ASM. The test module at the end of the program
listing gives the results that the comments say it should, but I cant
extrapolate them back to where the numbers come from:
i.e.
A = 01FF exp(07)
B = 7FFF exp(06)
A+B = 403F exp(07)
A*B = FF7E exp(12)
B-A = 7F7F exp(06)
B/A = 4000 exp(FA) remainder 3F
Cas any maths wizard explain to me what the decimal equivalents of these
numbers are? PLEASE?
--
erik
1997\05\12@155920
by
i93wag
|
As I understand it the float.asm file is part of the AN526 by
mistake. First I can't find any link in the AN526.pdf to floating
point maths. And secondly the code have some errors (specially the
division).
The autors in this example are using the following format:
Exponent: 8 bits or 1 file register
range -128 to 127
Mantissa: 16 bits or 2 file registers
bit# FEDC BA98 7654 3210
where bit F is the MSB and bit 0 ist the LSB.
Bit F shows the sign. Bit = 1 means the number is negative,
Bit F = 0 means the number is positive.
Each of the other bits are related to a power of two, like in
fix point numbers, but with negativ exponets:
bit E -> 2 exp(-2)
bit D -> 2 exp(-3)
bit C -> 2 exp(-4)
aso.
The best way to understand this is an example:
(using the test module at the end)
The equivalent of 1 is in floating point:
Mantissa: 2 exp(-2) Exponent 2 exp(2)
In notation of erik it is A = 4000h exp(02h).
For a test set B = 4000h exp(02h) too.
A+B = 4000h exp(03h) = [2exp(-2)]*[2exp(03h)] = 0.25*8 = 2
B-A = 0000h exp(02h) = [0]*[2exp(02h)] = 0
A*B = 4000h exp(02h) = 1
and a little more difficult:
A = 7.5 = {[2exp(-2)]+[2exp(-3)]+[2exp(-4)]+[2exp(-5)]}*[2exp(4)]
= 7800h exp(04h)
B = 2.5 = {[2exp(-2)]+[2exp(-4)]}*[2exp(4)]
= 5000h exp(04h)
A+B = 5000h exp(05h) = {[2exp(-2)]+[2exp(-4)]}*[2exp(5)]
= 0.25*32 + 0.0625*32 = 8 + 2
= 10
B-A = B000h exp(04h) = - 5000h exp(04h) (complement)
= -{[2exp(-2)]+[2exp(-4)]}*[2exp(4)]
= -(0.25*16 + 0.0625*16) = -(4 + 1)
= -5
A*B = 4B00h exp(06h) =
{[2exp(-2)]+[2exp(-5)]+2exp(-7)]
+[2exp(-8)]}*[2exp(6)]
= 0.25*64 + 0.03125*64 + 0.0078125
+ 0,00390625*64
= 16 + 2 + 0.5 + 0.25
= 18.75
This kind of floating point format is very unusualy, but very
useful for PICs, because it needs only 24 bit per number.
(IEEE needs 32 bit.)
Unfortunately the division don't works. If anybody have realy
need of a division function please conntact me by personal mail.
Jens Wagner
Leipzig, Germany
More... (looser matching)
- Last day of these posts
- In 1997
, 1998 only
- Today
- New search...