Skip to content

Commit

Permalink
Small tweaks to description.
Browse files Browse the repository at this point in the history
  • Loading branch information
jabr committed Apr 28, 2012
1 parent baacd7d commit b924330
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 6 additions & 6 deletions math/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

To avoid the overhead of bit-packing, I don't use any IEEE standard format. Instead, the numbers consist of two signed words. The first contains the mantissa/significand and the second the exponent.

The mantissa represents a fraction between -1 and 1. Its "value" is effectively `mantissa/32767`. The exponent is also signed (no basis), and represents a range from 2^(-32768) to 2^32766. 2^32767 (0x7fff) is a special case (infinity and NaN). This gives us a precision of ~3x10^(-5), and a ridiculous range of ~10^9863.
The mantissa represents a fraction between -2 and 2. Its "value" is effectively `mantissa/16384`. The exponent is also signed (no basis), and represents a range from 2^(-32768) to 2^32766. 2^32767 (0x7fff) is a special case (infinity and NaN). This gives us a precision of ~6x10^(-5), and a ridiculous range of ~10^9863.

Exponent 0x7fff is a special case: if the mantissa is 0, it means NaN; otherwise, it represents infinity with the sign from the mantissa.

Expand All @@ -15,11 +15,11 @@ The rough dasm16 implementation of basic arithmetic is simple and short; perform
### Todo

* Comparison functions: generally a few branching ops
* ceil/floor: Branch on sign, then?
* ceil/floor
* mod/remainder
* abs: a hardware AND
* inverse ?
* flip ?: hardware XOR
* abs
* inverse
* negate: hardware MLI (-32768 case?)
* constructor from base 10 ? (needs log and exp)
* string format ?
* assembler macro support for simple ops?
Expand All @@ -38,7 +38,7 @@ Anyway, most functions are based on the cordic algorithm. The core loop does 16
z = z - sign * e[i]
x = xt

`x, y, z` are fp numbers, and e is a lookup table of 16 fp numbers. Shifts on fps are a hardware SUB, and sign flipping on fps is a hardware XOR. Then there are three fp adds/subs.
`x, y, z` are fp numbers, and e is a lookup table of 16 fp numbers. Shifts on fps are a hardware SUB, and sign flipping on fps is a hardware MLI. Then there are three fp adds/subs.

#### Notes

Expand Down
8 changes: 6 additions & 2 deletions math/float.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def to(v):
e = int(math.ceil(math.log(math.fabs(v), 2)))
except:
e = 0
s = int((v / math.pow(2, e)) * 0x7fff)
s = int(math.ceil((v / math.pow(2, e)) * 0x7fff))
return (s, e)

def normalize(f, e):
Expand Down Expand Up @@ -85,7 +85,11 @@ def conversion_details(a):
conversion_details(b)

def number_details(af, ae):
print "{}b{} = {}".format(af, ae, to_float(af, ae))
print "{}b{} = {}\n = {:04x} {:04x} = {:016b} {:016b}".format(
af, ae, to_float(af, ae),
af & 0xffff, ae & 0xffff,
af & 0xffff, ae & 0xffff,
)

print "\n"

Expand Down

0 comments on commit b924330

Please sign in to comment.