This repository was archived by the owner on Aug 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathposit12.cpp
More file actions
80 lines (71 loc) · 1.19 KB
/
posit12.cpp
File metadata and controls
80 lines (71 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* ZPosit8 library
*
* Emanuele Ruffaldi 2017
*/
#include "posit12.hpp"
std::ostream & operator << (std::ostream & ons, const posit12 & p)
{
ons << "posit(" << p.uu() << ")" ;
return ons;
}
posit12::posit12(int a): v((FPT(a)).v)
{
}
posit12::posit12(float a): v((FPT(a)).v)
{
}
posit12::posit12(double a) : v((FPT(a)).v)
{
}
/**
Positive NUmber families
00000000
..
00001100 = .1875
..
00010000 = .25
..
00011000 = 0.375
..
00100001 = 0.5
..
00110000 = 0.75
..
01000000 = 1
..
01010000 = 1.5
..
01100000 = 2
...
01110000 = 4
...
01111111 = max
10000000 = infinity
*/
posit12 posit12::half() const
{
/*
int8_t aa = v < 0 ? -v : v;
if(has_neg_exponent()) // [0..1)
aa = aa >> 1; // down to 0
else if aa < 2 // [1..2)
aa = ((aa & 0x3F)|0x20);
else
aa = ((aa << 1) & 0x7F) | 0x40; // down to 01000000 == 0x4
return v < 0 ? -aa: aa;
*/
return (posit12)(as_posit()/(FPT)2);
}
posit12 posit12::twice() const
{
/*
int8_t aa = v < 0 ? -v : v;
if(has_neg_exponent()) // [0..1)
aa = (aa << 1) & 0x3F; // up to [1..]
else // [2...]
aa = (aa >> 1) | 0x40; // up to 011111111 without overflow
return v < 0 ? -aa: aa;
*/
return (posit12)(as_posit()*(FPT)2);
}