You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-5Lines changed: 20 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,12 @@
2
2
3
3
ieee754 is a Python module which finds the IEEE-754 representation of a floating point number. You can specify a precision given in the list below or you can even use your own custom precision.
4
4
<ul>
5
-
<li>Half Precision (16 bit: 1 bit for sign + 5 bits for exponent + 10 bits for mantissa)</li>
6
-
<li>Single Precision (32 bit: 1 bit for sign + 8 bits for exponent + 23 bits for mantissa)</li>
7
-
<li>Double Precision (64 bit: 1 bit for sign + 11 bits for exponent + 52 bits for mantissa)</li>
8
-
<li>Quadruple Precision (128 bit: 1 bit for sign + 15 bits for exponent + 112 bits for mantissa)</li>
9
-
<li>Octuple Precision (256 bit: 1 bit for sign + 19 bits for exponent + 236 bits for mantissa)</li>
5
+
<li>Half Precision (16 bit: 1 bit for sign + 5 bits for exponent + 10 bits for mantissa)</li>
6
+
<li>Single Precision (32 bit: 1 bit for sign + 8 bits for exponent + 23 bits for mantissa)</li>
7
+
<li>Double Precision (64 bit: 1 bit for sign + 11 bits for exponent + 52 bits for mantissa)</li>
8
+
<li>Quadruple Precision (128 bit: 1 bit for sign + 15 bits for exponent + 112 bits for mantissa)</li>
9
+
<li>Octuple Precision (256 bit: 1 bit for sign + 19 bits for exponent + 236 bits for mantissa)</li>
10
+
</ul>
10
11
11
12
## Prerequisites
12
13
@@ -20,9 +21,20 @@ $ pip install ieee754
20
21
```
21
22
22
23
## Using
24
+
23
25
After installation, you can import ieee754 and use it in your projects.
24
26
27
+
### Simplest Example
28
+
29
+
The simplest example is to use the desired precision IEEE-754 representation of a floating point number. You can import the desired precision from ieee754 and use it like this. The available precisions are half, single, double, quadruple and octuple.
30
+
```Python
31
+
from ieee754 import double
32
+
33
+
print(double(13.375))
34
+
```
35
+
25
36
### Default Options
37
+
26
38
Default precision is Double Precision and you can get the output by just calling the instance as a string.
27
39
```Python
28
40
from ieee754 importIEEE754
@@ -40,6 +52,7 @@ print(a.json())
40
52
```
41
53
42
54
### Select a Precision
55
+
43
56
You can use Half (p=0), Single (p=1), Double (p=2), Quadrupole (p=3) or Octuple precision (p=4).
44
57
```Python
45
58
from ieee754 importIEEE754
@@ -50,6 +63,7 @@ for p in range(5):
50
63
```
51
64
52
65
### Use the Precision Name as an Interface
66
+
53
67
You can use the precision name as an interface to get the IEEE-754 representation of a floating point number. With this method you can get the IEEE-754 representation of a floating point number without creating an instance.
54
68
```Python
55
69
from ieee754 import half, single, double, quadruple, octuple
@@ -63,6 +77,7 @@ print(octuple(x))
63
77
```
64
78
65
79
### Using a Custom Precision
80
+
66
81
You can force exponent, and mantissa size by using force_exponent and force_mantissa parameters to create your own custom precision.
67
82
```Python
68
83
a = IEEE754(x, force_exponent=6, force_mantissa=12)
0 commit comments