1 module aftermath;
2 
3 private
4 {
5 	import std.algorithm;
6 	import std.bigint;
7 	import std.conv;
8 	import std.math;
9 	import std.stdio;
10 	import std..string;
11 	import std.typecons;
12 	
13 	// template for adding setter/getter
14 	template addProperty(T, string propertyName, string defaultValue = T.init.to!string)
15 	{	 
16 		const char[] addProperty = format(
17 			`
18 			private %2$s %1$s = %4$s;
19 	 
20 			void set%3$s(%2$s %1$s)
21 			{
22 				this.%1$s = %1$s;
23 			}
24 	 
25 			%2$s get%3$s()
26 			{
27 				return %1$s;
28 			}
29 			`,
30 			"_" ~ propertyName.toLower,
31 			T.stringof,
32 			propertyName,
33 			defaultValue
34 			);
35 	}
36 	
37 	auto twoComplement(T)(T n, T bits)
38 	{
39 		return ((cast(T) 1 << bits) - n) % (cast(T) 1 << bits);
40 	}
41 
42 	auto oneComplement(T)(T n, T bits)
43 	{
44 		return (cast(T) 1 << bits) - n - cast(T) 1;
45 	}
46 	
47 	auto countBits(T)(T n)
48 	{
49 		T count;
50 		if (n == 0)
51 		{
52 			count++;
53 		}
54 		else
55 		{
56 			while (n != 0)
57 			{
58 				n >>= 1;
59 				count++;
60 			}
61 		}
62 		return count;
63 	}
64 
65 	auto setBit(T)(T n, T i)
66 	{
67 		return n | (cast(T) 1 << i);
68 	}
69 
70 	auto getBit(T)(T n, T i)
71 	{
72 		return (n >> i) & cast(T) 1;
73 	}
74 	
75 	auto toggleBit(T)(T n, T i)
76 	{
77 		return n ^ (cast(T) 1 << i);
78 	}
79 	
80 	auto unsetBit(T)(T n, T i)
81 	{
82 		return (n | (cast(T) 1 << i)) ^ (cast(T) 1 << i);
83 	}
84 
85 	auto createMask(T)(T n, T k)
86 	{
87 		return ((cast(T) 1 << n) - cast(T) 1) << k;
88 	}
89 	
90 	auto extractBitField(T)(T x, T n, T k)
91 	{
92 		return (x & createMask(n, k)) >> k;
93 	}
94 	
95 	auto lastSettedBit(T)(T n)
96 	{
97 		return countBits(n) - cast(T) 1;
98 	}
99 	
100 	auto lastUnsettedBit(T)(T n)
101 	{
102 		return lastSettedBit(
103 			oneComplement(
104 				n, 
105 				countBits(n)
106 			)
107 		);
108 	}
109 	
110 	auto countTrailingZeroes(T)(T n)
111 	{
112 		if (n == 0)
113 		{
114 			return 0;
115 		}
116 		else
117 		{
118 			return countBits(n & (-n)) - cast(T) 1;
119 		}
120 	}
121 	
122 	auto removeTrailingZeroes(T)(T n)
123 	{
124 		if (n == 0)
125 		{
126 			return 0;
127 		}
128 		else
129 		{
130 			return n >> countTrailingZeroes(n);
131 		}
132 	}
133 	
134 	auto ceilLog2(T)(T n)
135 	{
136 		T x = lastSettedBit(n);
137 		return x + cast(T) (n != (cast(T) 1 << x));
138 	}
139 	
140 	auto floorLog2(T)(T n)
141 	{
142 		return countBits(n) - cast(T) 1;
143 	}
144 	
145 	auto nextPowerOfTwo(T)(T n)
146 	{
147 		return cast(T) 1 << ceilLog2(n);
148 	}
149 	
150 	auto alignValues(T, S)(T a, S b)
151 	{
152 		auto lengthA = countBits(a);
153 		auto lengthB = countBits(b);
154 		
155 		if (lengthA > lengthB)
156 		{
157 			b <<= (lengthA - lengthB);
158 		}
159 		else
160 		{
161 			if (lengthA < lengthB)
162 			{
163 				a <<= lengthB - lengthA;
164 			}
165 		}
166 		
167 		auto trailingA = countTrailingZeroes(a);
168 		auto trailingB = countTrailingZeroes(b);
169 		
170 		a >>= min(trailingA, trailingB);
171 		b >>= min(trailingA, trailingB);
172 		
173 		return tuple(a, b);
174 	}
175 	
176 	// internals of double
177 	class DoubleComponents
178 	{
179 		mixin(addProperty!(long, "Value"));
180 		mixin(addProperty!(long, "Sign"));
181 		mixin(addProperty!(long, "Exponent"));
182 		mixin(addProperty!(long, "Fraction"));
183 		
184 		this()
185 		{
186 			
187 		}
188 		
189 		// extract data from double
190 		auto fromDouble(double number)
191 		{
192 			// bitwise conversion to ulong
193 			_value = *(cast(ulong*) &number);
194 			// sign extraction
195 			_sign = _value >> 63;
196 			// exponent extraction
197 			_exponent = ((_value & ((1UL << 63) - 1)) >> 52) - 1023;
198 			// fraction extraction
199 			_fraction = (1UL << 52) | (_value & ((1UL << 52) - 1));
200 		}
201 	}
202 	
203 	// representation of internal posit structure
204 	class PositComponents
205 	{
206 		// 0 or 1 in begin of regime
207 		mixin(addProperty!(long, "RegimeSign"));
208 		// sign bit
209 		mixin(addProperty!(long, "Sign"));
210 		// regime
211 		mixin(addProperty!(long, "Regime"));
212 		// exponent
213 		mixin(addProperty!(long, "Exponent"));
214 		// fraction
215 		mixin(addProperty!(long, "Fraction"));
216 		// regime length
217 		mixin(addProperty!(long, "RegimeLength"));
218 		// exponent length
219 		mixin(addProperty!(long, "ExponentLength"));
220 		// fraction length
221 		mixin(addProperty!(long, "FractionLength"));
222 		
223 		this()
224 		{
225 			
226 		}
227 		
228 		// extract component from long value (value is bit pattern)
229 		auto fromLong(long numberOfBits, long exponentSize)(long number)
230 		{
231 			long _number = number;
232 			_sign = getBit(_number, numberOfBits  - 1);
233 			
234 			if (_sign == 1)
235 			{
236 				_number = twoComplement(_number, numberOfBits);
237 			}
238 			
239 			_regimesign = getBit(_number, numberOfBits - 2);
240 				        
241 	        if (_regimesign == 0)
242 	        {
243 	            _regimelength = numberOfBits - lastSettedBit(_number) - 1;
244 			}
245 	        else
246 	        {
247 	            _regimelength = numberOfBits - lastUnsettedBit(_number) - 1;
248 			}
249 			
250 			
251 	        _exponentlength = max(0, min(exponentSize, numberOfBits - 1 - _regimelength));
252 	        _fractionlength = max(0, numberOfBits - 1 - _regimelength - _exponentlength);
253 	        
254 	        if (_regimesign == 0)
255 	        {
256 				_regime = - _regimelength + 1;
257 	        }  
258 	        else
259 	        { 
260 				_regime = _regimelength - 2;
261 			}
262 			
263 	        
264 	        _exponent = extractBitField(_number, _exponentlength, _fractionlength) << (exponentSize - _exponentlength);
265 	        _fraction = removeTrailingZeroes(
266 				setBit(
267 					extractBitField(_number, _fractionlength, 0), _fractionlength)
268 				);
269 		}
270 	}
271 	
272 	// posit container
273 	template PositContainer(uint size)
274 	{
275 		static if (size == 8)
276 			alias PositContainer = ubyte;
277 		else static if (size == 16)
278 			alias PositContainer = ushort;
279 		else static if (size == 32)
280 			alias PositContainer = uint;
281 		else static if (size == 64)
282 			alias PositContainer = ulong;
283 		else
284 			static assert(0);
285 	}
286 	
287 	class Posit(uint numberOfBits, uint exponentSize)
288 	{
289 		private
290 		{
291 			// type for internal's of posit
292 			alias Unum = PositContainer!numberOfBits;
293 			// internal representation of posit
294 			mixin(addProperty!(Unum, "Unum"));
295 			// size of posit in bit
296 			enum NBITS = numberOfBits;    		 
297 			// maximal size of exponent in bit
298 			enum ES = exponentSize;		
299 			// useed
300 			enum USEED = 2 ^^ (2 ^^ ES);
301 			// minimal *positive* value (bit pattern)
302 			enum MINPOS = 1;
303 			// maximal *positive* value (bit pattern)
304 			enum MAXPOS = (2 ^^ (NBITS - 1)) - 1; 
305 			// NaR (not a real) pattern
306 			enum NOT_A_REAL = 2 ^^ (NBITS - 1);
307 			// zero pattern
308 			enum ZERO = 0;
309 			// number of patterns
310 			enum NPAT = 2 ^^ NBITS;
311 			
312 			PositComponents components = new PositComponents;
313 		}
314 		
315 		
316 		this()
317 		{
318 			
319 		}
320 		
321 		// construct posit from his elements: (sign, scale, fraction)
322 		auto construct(T)(T sign, T scale, T fraction)
323 		{
324 			Posit!(NBITS, ES) posit = new Posit!(NBITS, ES);
325 
326 			if (fraction == 0)
327 			{
328 				return posit;
329 			}
330 		
331 			long n = 0;
332 			long regime = scale >> ES;
333 			long exponent = scale & createMask(ES, 0);
334 			
335 			long regimeLength;
336 			
337 			if (regime >= 0)
338 			{
339 				regimeLength = regime + 2;
340 			}
341 			else 
342 			{
343 				regimeLength = - regime + 1;
344 			}
345 			
346 			if (regimeLength >= (NBITS + 1))
347 			{
348 				if (regime >= 0)
349 				{
350 					posit.fromBits(MAXPOS);
351 				}
352 				else
353 				{
354 					posit.fromBits(MINPOS);
355 				}
356 		      
357 				if (sign == 1)
358 				{
359 					auto unum = posit.getUnum;
360 					posit.fromBits(
361 						twoComplement(_unum.to!long, NBITS).to!Unum
362 					);
363 				}
364 		        
365 		        return posit;
366 		    }
367 		    
368 		    if (regime >= 0)
369 		    {
370 		        n |= createMask(regimeLength - 1, NBITS - regimeLength);
371 			}
372 		    else 
373 		    {
374 				if (NBITS - 1 >= regimeLength)
375 				{
376 		            n |= setBit(n, NBITS - 1 - regimeLength);
377 				}
378 			}
379 				
380 			long exponentBits = min(ES, NBITS - 1 - regimeLength);
381 		    long fractionBits = NBITS - 1 - regimeLength - exponentBits;
382 		    
383 		    
384 		    fraction = removeTrailingZeroes(fraction);
385 		    long fractionLength = countBits(fraction) - 1;
386 			fraction &= 2 ^^ (countBits(fraction) - 1) - 1;
387 			
388 			long trailingBits = NBITS - 1 - regimeLength;
389 			long expFrac = removeTrailingZeroes(exponent << (fractionLength) | fraction);
390 			
391 			long expFracBits;
392 			
393 			if (fractionLength == 0)
394 			{
395 		         expFracBits = ES - countTrailingZeroes(exponent);
396 		    }
397 		    else
398 		    {
399 		         expFracBits = ES + fractionLength;
400 		    }
401 		    
402 		    if (trailingBits < expFracBits)
403 		    {
404 					long mask = expFrac & createMask(expFracBits - trailingBits, 0);
405 		            long overflown = expFrac & mask;
406 		            n |= expFrac >> (expFracBits - trailingBits);
407 		            auto overflowMask = (1L << (expFracBits - trailingBits - 1L));
408 		            
409 		            
410 		            if (overflown == overflowMask)
411 		            {
412 		                if (getBit(expFrac, expFracBits - trailingBits) == 1)
413 		                {
414 		                    n += 1;
415 		                }
416 		            }
417 		            else
418 		            {
419 						if (overflown > overflowMask)
420 						{
421 							n += 1;
422 						}
423 						else
424 						{
425 							// for another way actions don't needed
426 						}
427 		            }      
428 		     }
429 		     else
430 		     {
431 		         n |= expFrac << (trailingBits - expFracBits);
432 		     }
433 		     
434 		     if (sign == 0)
435 		     {
436 		         posit.fromBits(n);
437 		     }
438 		     else
439 		     {
440 		         posit.fromBits(twoComplement(n.to!long, NBITS));
441 		     }
442 		     
443 			 return posit;
444 		}
445 		
446 		// decoding components of posit
447 		PositComponents decode() @property
448 		{
449 			components.fromLong!(NBITS, ES)(_unum);
450 			return components;
451 		}
452 		
453 		// set from bit pattern
454 		auto fromBits(T)(T bitPattern)
455 		{
456 			this.setUnum(bitPattern.to!Unum);
457 			decode;
458 		}
459 		
460 		// set from double
461 		auto fromDouble(double x)
462 		{
463 			if (x == 0.0)
464 			{
465 				_unum = ZERO;
466 			}
467 			else
468 			{
469 				if (x.isNaN || x.isInfinity)
470 				{
471 					_unum = NOT_A_REAL;
472 				}
473 				else
474 				{
475 					DoubleComponents dc = new DoubleComponents;
476 					dc.fromDouble(x);
477 					
478 					_unum = construct(
479 						dc.getSign,
480 						dc.getExponent,
481 						dc.getFraction
482 					).getUnum;
483 					decode;
484 				}
485 			}
486 		}
487 		
488 		// set from integer
489 		auto fromInteger(int x)
490 		{
491 			if (x == 0)
492 			{
493 				_unum = ZERO;
494 			}
495 			else
496 			{
497 				auto sign = (x >= 0) ? 0 : 1;
498 				if (sign == 1)
499 				{
500 					x = abs(x);
501 				}
502 				auto exponent = countBits(x) - 1;
503 				auto fraction = x;
504 				_unum = construct(
505 					sign,
506 					exponent,
507 					fraction
508 					).getUnum;
509 					decode;
510 			}
511 		}
512 		
513 		// is maximal value of posit ?
514 		bool isMax() @property
515 		{
516 			return (_unum == MAXPOS);
517 		}
518 		
519 		// is minimal value of posit ?
520 		bool isMin() @property
521 		{
522 			return (_unum == MINPOS);
523 		}
524 		
525 		// is a +/- infinity ?
526 		bool isNaR() @property
527 		{
528 			return (_unum == NOT_A_REAL);
529 		}
530 		
531 		// is valid posit ?
532 		bool isValid() @property
533 		{
534 			return ((0 <= _unum) && (_unum < NPAT));
535 		}
536 		
537 		// is a posit zero ?
538 		bool isZero() @property
539 		{
540 			return (_unum == ZERO);
541 		}
542 		
543 		// addition
544 		auto opBinary(string op)(Posit!(NBITS, ES) rhs) if (op == "+")
545 		{
546 			if (_unum == 0)
547 			{
548 				return rhs;
549 			}
550 			
551 			if (rhs.isZero)
552 			{
553 				return this;
554 			}
555 			else
556 			{
557 				if ((rhs.isNaR) || (_unum == NOT_A_REAL))
558 				{
559 					return rhs;
560 				}
561 			}
562 			
563 			PositComponents components2 = new PositComponents;
564 			decode;
565 			components2.fromLong!(NBITS, ES)(rhs.getUnum);
566 			
567 			auto fractions = alignValues(components.getFraction, components2.getFraction);
568 			long fraction1 = fractions[0];
569 			long fraction2 = fractions[1];
570 			long scale1 = 2 ^^ ES * components.getRegime + components.getExponent;
571 			long scale2 = 2 ^^ ES * components2.getRegime + components2.getExponent;
572 			long scale = max(scale1, scale2);
573 			
574 			long estimatedLength;
575 			
576 			if (scale1 > scale2)
577 			{
578 	            fraction1 <<= scale1 - scale2;
579 	            estimatedLength = countBits(fraction1);
580 	        }
581 	        else
582 	        {
583 	            fraction2 <<= scale2 - scale1;
584 	            estimatedLength = countBits(fraction2);
585 	        }
586 	        
587 	        
588 	        long fraction = ((-1) ^^ components.getSign * fraction1) + ((-1) ^^ components2.getSign * fraction2);
589 	        long sign = (fraction < 0) ? 1 : 0;
590 	        fraction = abs(fraction);
591 	        
592 	        long resultLength = countBits(fraction);
593 	        scale += resultLength - estimatedLength;
594 	        fraction = removeTrailingZeroes(fraction);
595 			
596 			return construct(sign, scale, fraction);
597 		}
598 		
599 		// subtraction
600 		auto opBinary(string op)(Posit!(NBITS, ES) rhs) if (op == "-")
601 		{
602 			return (this + (-rhs));
603 		}
604 		
605 		// conversion to int
606 		int opCast(T : int)()
607 		{
608 			if (_unum == 0)
609 			{
610 				return 0;
611 			}
612 			else
613 			{
614 				if (_unum == NOT_A_REAL)
615 				{
616 					return T.max;
617 				}
618 				else
619 				{
620 					return (cast(double) this).to!int;
621 				}
622 			}
623 		}
624 	
625 		// conversion to double
626 		double opCast(T : double)()
627 		{
628 		    if (_unum == 0)
629 			{
630 				return 0.0;
631 			}
632 			else
633 			{
634 				if (_unum == NOT_A_REAL)
635 				{
636 					return double.nan;
637 				}
638 				else
639 				{
640 					decode;
641 					double fraction = components.getFraction;
642 					double n = countBits(components.getFraction) - 1;
643 					return (
644 						(-1.0) ^^ components.getSign * 
645 							2.0 ^^ (2.0 ^^ ES * components.getRegime + components.getExponent - n) * 
646 							fraction
647 						);
648 				}
649 			}
650 		}
651 		
652 	    // multiplication
653 	    auto opBinary(string op)(Posit!(NBITS, ES) rhs) if (op == "*")
654 		{
655 			if (this.isZero || this.isNaR)
656 			{
657 				return this;
658 			}
659 			else
660 			{
661 				if (rhs.isZero || rhs.isNaR)
662 				{
663 					return rhs;
664 				}
665 			}
666 			
667 			PositComponents components2 = new PositComponents;
668 			decode;
669 			components2.fromLong!(NBITS, ES)(rhs.getUnum);
670 			
671 			long sign = components.getSign ^ components2.getSign;
672 			
673 			long scale = (2 ^^ ES * (components.getRegime + components2.getRegime) + components.getExponent + components2.getExponent );
674 	        long fraction = components.getFraction * components2.getFraction;
675 	
676 	        long fa = floorLog2(components.getFraction);
677 	        long fb = floorLog2(components2.getFraction);
678 	        long fc = floorLog2(fraction);
679 	        
680 	        scale += fc - fa - fb;
681 	        
682 	        return construct(sign, scale, fraction);
683 		}
684 		
685 		// division
686 		auto opBinary(string op)(Posit!(NBITS, ES) rhs) if (op == "/")
687 		{
688 			if (this.isZero || this.isNaR)
689 			{
690 				return this;
691 			}
692 			else
693 			{
694 				if (rhs.isZero || rhs.isNaR)
695 				{
696 					return rhs;
697 				}
698 			}
699 			
700 			PositComponents components2 = new PositComponents;
701 			decode;
702 			components2.fromLong!(NBITS, ES)(rhs.getUnum);
703 			
704 			long fraction1 = components.getFraction;
705 			
706 			if ((fraction1 & (fraction1 - 1)) ==  0)
707 			{
708 				return this * rhs.reciprocal;
709 			}
710 			else
711 			{
712 				long sign = components.getSign ^ components2.getSign;
713 				long scale =  (2 ^^ ES * (components.getRegime - components2.getRegime) + components.getExponent - components2.getExponent);
714 				long fraction2 = components2.getFraction;
715 				auto fractions = alignValues(fraction1, fraction2);
716 				import std.bigint;
717 				auto n = BigInt(fractions[0].to!string);
718 				fraction2 = fractions[1];
719 				long fa = floorLog2(n << (NBITS * 4)).to!long;
720 				long fb = floorLog2(fraction2);
721 				auto fraction = (n << (NBITS * 4) / fraction2).to!long;
722 				long fc = floorLog2(fraction);
723 	        
724 				scale -= fa - fb - fc;
725 				
726 				return construct(sign, scale, fraction);
727 			}
728 		}
729 		
730 		override int opCmp(Object o)
731 		{
732 			int result;
733 			if (typeid(o) == typeid(Posit!(NBITS, ES)))
734 			{
735 				auto a = this.toSignedInteger;
736 				auto b = (cast(Posit!(NBITS, ES)) o).toSignedInteger;
737 				
738 				if (a > b)
739 				{
740 					result = 1;
741 				}
742 				else
743 				{
744 					if (a < b)
745 					{
746 						result = -1;
747 					}
748 					else
749 					{
750 						result = 0;
751 					}
752 				}
753 			}
754 			return result;
755 		}
756 		
757 		// unary minus
758 		auto opUnary(string op)() if (op == "-")
759 	    {
760 			Posit!(NBITS, ES) posit = new Posit!(NBITS, ES);
761 	        posit.fromBits(
762 				twoComplement(_unum.to!ulong, NBITS)
763 			);
764 			return posit;
765 	    }
766 	    
767 		// reciprocal
768 		auto reciprocal()
769 	    {
770 			Posit!(NBITS, ES) posit = new Posit!(NBITS, ES);
771 			long bits = unsetBit(
772 				twoComplement(_unum.to!long, NBITS),
773 				NBITS - 1
774 			);
775 			posit.fromBits(bits);
776 			
777 			return posit;
778 		}
779 		
780 		version (linux)
781 		{
782 			// nice binary representation with color
783 			string toBinaryFormatted()
784 			{
785 				// for sign format (sign is string) (red colored)
786 				enum SIGN_FORMAT = "\u001b[41m\u001b[97m\u001b[1m%s\u001b[0m";
787 				// for regime format (regime is string) (yellow colored)
788 				enum REGIME_FORMAT = "\u001b[43m\u001b[97m\u001b[1m%s\u001b[0m";
789 				// for exponent format (exponent is string) (blue colored)
790 				enum EXPONENT_FORMAT = "\u001b[44m\u001b[97m\u001b[1m%s\u001b[0m";
791 				// for fraction format (fraction is string) (black colored)
792 				enum FRACTION_FORMAT = "\u001b[40m\u001b[97m\u001b[1m%s\u001b[0m";
793 				
794 				// fill the data structure with current data from posit
795 				decode;
796 				string formattedData;
797 				
798 				// binary string from number
799 				auto rawData = ("%0." ~ NBITS.to!string ~ "b").format(_unum);
800 				
801 				// rawData[0] - first digit of binary representation, i.e sign of posit
802 				formattedData ~= SIGN_FORMAT.format(rawData[0].to!string);
803 				// position of posits components in unsigned his representation
804 				auto position = 1 + components.getRegimeLength;
805 				// regime started at second position
806 				formattedData ~= REGIME_FORMAT.format(rawData[1..position]);
807 				
808 				// if exponent exists
809 				if (components.getExponentLength != 0)
810 				{
811 					formattedData ~= EXPONENT_FORMAT.format(rawData[position..position+components.getExponentLength]);
812 					position += components.getExponentLength;
813 				}
814 				
815 				// if fraction exists
816 				if (components.getFractionLength != 0)
817 				{
818 					formattedData ~= FRACTION_FORMAT.format(rawData[position..$]);
819 				}
820 				
821 				return formattedData;
822 			}
823 		}
824 
825 		// to signed integer
826 		auto toSignedInteger()
827 		{
828 			template SignedType(T)
829 			{
830 				static if (is(T == ubyte))
831 					alias SignedType = byte;
832 				else static if (is(T== ushort))
833 					alias SignedType = short;
834 				else static if (is(T == uint))
835 					alias SignedType = int;
836 				else static if (is(T == ulong))
837 					alias SignedType = long;
838 				else
839 					static assert(0);
840 			}
841 			
842 			alias SignedUnum = SignedType!Unum;
843 			
844 			SignedUnum unum = cast(SignedUnum) _unum;
845 			
846 			return unum;
847 		}
848 		
849 		// to unsigned integer
850 		auto toUnsignedInteger()
851 		{
852 			return _unum;
853 		}
854 		
855 		// string representation
856 		override string toString()
857 		{
858 			enum string positFormat = `Posit{%d, %d}(0x%0.` ~ to!string(NBITS >> 2) ~ `x)[%0.32f]`;
859 			
860 			return positFormat.format(
861 				NBITS,
862 				ES,
863 				_unum,
864 				cast(double) this
865 			);
866 		}
867 		
868 		alias components this;
869 	}
870 }
871 
872 alias Posit8 = Posit!(8, 0);
873 alias Posit16 = Posit!(16, 1);
874 alias Posit32 = Posit!(32, 2);
875 alias Posit64 = Posit!(64, 3);
876 alias SoftFloat = Posit!(8, 2);