correcting use of uint32_t where uint64_t should be used
[sfpy.git] / README.md
1 # sfpy
2 softfloat and softposit in Python
3 * support for softfloat float16, float32, and float64
4 * support for softposit posit8, quire8, posit16, quire16, posit32, and quire32
5
6 ## Installation
7 On most linux distros with CPython 2.7, 3.4, 3.5, 3.6, or 3.7, sfpy should work out of the box:
8
9 ```
10 pip install sfpy
11 ```
12
13 Under the hood, sfpy uses Cython to create bindings for the softposit and softfloat C libraries.
14 The building instructions are tested on Ubuntu 16.04 - for other platforms they may need some
15 adaptation.
16
17 ## Demo
18 ```
19 >>> import sfpy
20 >>> from sfpy import *
21 >>> a, b = Float16(1.3), Float16(1.4)
22 >>> a * b - a / b
23 Float16(0.89208984375)
24 >>> sfpy.float.flag_get_inexact()
25 True
26 >>> a += b
27 >>> a
28 Float16(2.69921875)
29 >>>
30 >>> x, y = Posit16(3.0), Posit16(3)
31 >>> x
32 Posit16(3.0)
33 >>> x.bits
34 22528
35 >>> y
36 Posit16(2.9802322387695312e-08)
37 >>> y.bits
38 3
39 >>> x * y
40 Posit16(8.940696716308594e-08)
41 >>> acc = Posit16(0)
42 >>> for i in range(10000):
43 ... acc = acc.fma(x, y)
44 ...
45 >>> acc
46 Posit16(1.9073486328125e-06)
47 >>> acc.bits
48 24
49 >>> q = Quire16(0)
50 >>> for i in range(10000):
51 ... q.iqma(x, y)
52 ...
53 >>> q
54 Quire16(0.00089263916015625)
55 >>> q.bits
56 64424509440000
57 >>> q.to_posit()
58 Posit16(0.00089263916015625)
59 >>> q.to_posit().bits
60 490
61 ```
62
63 ## Building
64 See [BUILDING](https://github.com/billzorn/sfpy/blob/master/BUILDING.md).