1 from libc.stdint cimport *
5 # special values and C helpers
7 cdef _p8_one = cposit.ui32_to_p8(1)
8 cdef _p16_one = cposit.ui32_to_p16(1)
10 cdef inline cposit.posit8_t _p8_neg(cposit.posit8_t f):
14 cdef inline cposit.posit16_t _p16_neg(cposit.posit16_t f):
18 cdef inline cposit.posit8_t _p8_abs(cposit.posit8_t f):
19 f.v = <uint8_t> abs(<int8_t> f.v)
22 cdef inline cposit.posit16_t _p16_abs(cposit.posit16_t f):
23 f.v = <uint16_t> abs(<int16_t> f.v)
29 # the wrapped posit value
30 cdef cposit.posit8_t _c_posit
32 # factory function constructors that bypass __init__
35 cdef Posit8 from_c_posit(cposit.posit8_t f):
36 """Factory function to create a Posit8 object directly from
39 cdef Posit8 obj = Posit8.__new__(Posit8)
44 def from_bits(uint8_t value):
45 """Factory function to create a Posit8 object from a bit pattern
46 represented as an integer.
48 cdef Posit8 obj = Posit8.__new__(Posit8)
49 obj._c_posit.v = value
53 def from_double(double value):
54 """Factory function to create a Posit8 object from a double.
56 cdef Posit8 obj = Posit8.__new__(Posit8)
57 obj._c_posit = cposit.convertDoubleToP8(value)
60 # convenience interface for use inside Python
62 def __init__(self, value):
63 if isinstance(value, int):
64 self._c_posit.v = value
67 self._c_posit = cposit.convertDoubleToP8(f)
70 return cposit.convertP8ToDouble(self._c_posit)
73 return int(cposit.convertP8ToDouble(self._c_posit))
76 return repr(cposit.convertP8ToDouble(self._c_posit))
79 return 'Posit8(' + repr(cposit.convertP8ToDouble(self._c_posit)) + ')'
81 cpdef uint8_t get_bits(self):
82 return self._c_posit.v
83 bits = property(get_bits)
87 cpdef Posit8 neg(self):
88 cdef cposit.posit8_t f = _p8_neg(self._c_posit)
89 return Posit8.from_c_posit(f)
94 cpdef Posit8 abs(self):
95 cdef cposit.posit8_t f = _p8_abs(self._c_posit)
96 return Posit8.from_c_posit(f)
101 cpdef Posit8 round(self):
102 cdef cposit.posit8_t f = cposit.p8_roundToInt(self._c_posit)
103 return Posit8.from_c_posit(f)
108 cpdef Posit8 add(self, Posit8 other):
109 cdef cposit.posit8_t f = cposit.p8_add(self._c_posit, other._c_posit)
110 return Posit8.from_c_posit(f)
112 def __add__(self, Posit8 other):
113 return self.add(other)
115 cpdef Posit8 sub(self, Posit8 other):
116 cdef cposit.posit8_t f = cposit.p8_sub(self._c_posit, other._c_posit)
117 return Posit8.from_c_posit(f)
119 def __sub__(self, Posit8 other):
120 return self.sub(other)
122 cpdef Posit8 mul(self, Posit8 other):
123 cdef cposit.posit8_t f = cposit.p8_mul(self._c_posit, other._c_posit)
124 return Posit8.from_c_posit(f)
126 def __mul__(self, Posit8 other):
127 return self.mul(other)
129 cpdef Posit8 fma(self, Posit8 a2, Posit8 a3):
130 cdef cposit.posit8_t f = cposit.p8_mulAdd(self._c_posit, a2._c_posit, a3._c_posit)
131 return Posit8.from_c_posit(f)
133 cpdef Posit8 fam(self, Posit8 a1, Posit8 a2):
134 cdef cposit.posit8_t f = cposit.p8_mulAdd(a1._c_posit, a2._c_posit, self._c_posit)
135 return Posit8.from_c_posit(f)
137 cpdef Posit8 div(self, Posit8 other):
138 cdef cposit.posit8_t f = cposit.p8_div(self._c_posit, other._c_posit)
139 return Posit8.from_c_posit(f)
141 def __truediv__(self, Posit8 other):
142 return self.div(other)
144 cpdef Posit8 sqrt(self):
145 cdef cposit.posit8_t f = cposit.p8_sqrt(self._c_posit)
146 return Posit8.from_c_posit(f)
148 # in-place arithmetic
150 cpdef void ineg(self):
151 self._c_posit = _p8_neg(self._c_posit)
153 cpdef void iabs(self):
154 self._c_posit = _p8_abs(self._c_posit)
156 cpdef void iround(self):
157 self._c_posit = cposit.p8_roundToInt(self._c_posit)
159 cpdef void iadd(self, Posit8 other):
160 self._c_posit = cposit.p8_add(self._c_posit, other._c_posit)
162 def __iadd__(self, Posit8 other):
166 cpdef void isub(self, Posit8 other):
167 self._c_posit = cposit.p8_sub(self._c_posit, other._c_posit)
169 def __isub__(self, Posit8 other):
173 cpdef void imul(self, Posit8 other):
174 self._c_posit = cposit.p8_mul(self._c_posit, other._c_posit)
176 def __imul__(self, Posit8 other):
180 cpdef void ifma(self, Posit8 a2, Posit8 a3):
181 self._c_posit = cposit.p8_mulAdd(self._c_posit, a2._c_posit, a3._c_posit)
183 cpdef void ifam(self, Posit8 a1, Posit8 a2):
184 self._c_posit = cposit.p8_mulAdd(a1._c_posit, a2._c_posit, self._c_posit)
186 cpdef void idiv(self, Posit8 other):
187 self._c_posit = cposit.p8_div(self._c_posit, other._c_posit)
189 def __itruediv__(self, Posit8 other):
193 cpdef void isqrt(self):
194 self._c_posit = cposit.p8_sqrt(self._c_posit)
198 cpdef bint eq(self, Posit8 other):
199 return cposit.p8_eq(self._c_posit, other._c_posit)
201 cpdef bint le(self, Posit8 other):
202 return cposit.p8_le(self._c_posit, other._c_posit)
204 cpdef bint lt(self, Posit8 other):
205 return cposit.p8_lt(self._c_posit, other._c_posit)
207 def __lt__(self, Posit8 other):
208 return self.lt(other)
210 def __le__(self, Posit8 other):
211 return self.le(other)
213 def __eq__(self, Posit8 other):
214 return self.eq(other)
216 def __ne__(self, Posit8 other):
217 return not self.eq(other)
219 def __ge__(self, Posit8 other):
220 return other.le(self)
222 def __gt__(self, Posit8 other):
223 return other.lt(self)
225 # conversion to other posit types
228 cdef cposit.posit16_t f = cposit.p8_to_p16(self._c_posit)
229 return Posit16.from_c_posit(f)
231 cpdef to_quire(self):
232 cdef cposit.quire8_t f
234 f = cposit.q8_fdp_add(f, self._c_posit, _p8_one)
235 return Quire8.from_c_quire(f)
240 # the wrapped quire value
241 cdef cposit.quire8_t _c_quire
243 # factory function constructors that bypass init
246 cdef Quire8 from_c_quire(cposit.quire8_t f):
247 """Factory function to create a Quire8 object directly from
250 cdef Quire8 obj = Quire8.__new__(Quire8)
255 def from_bits(uint32_t value):
256 """Factory function to create a Quire8 object from a bit pattern
257 represented as an integer.
259 cdef Quire8 obj = Quire8.__new__(Quire8)
260 obj._c_quire.v = value
263 # convenience interface for use inside Python
265 def __init__(self, value):
266 if isinstance(value, int):
267 self._c_quire.v = value
270 cposit.q8_clr(self._c_quire)
271 self._c_quire = cposit.q8_fdp_add(self._c_quire, cposit.convertDoubleToP8(f), _p8_one)
274 return cposit.convertP8ToDouble(cposit.q8_to_p8(self._c_quire))
277 return int(cposit.convertP8ToDouble(cposit.q8_to_p8(self._c_quire)))
280 return repr(cposit.convertP8ToDouble(cposit.q8_to_p8(self._c_quire)))
283 return 'Quire8(' + repr(cposit.convertP8ToDouble(cposit.q8_to_p8(self._c_quire))) + ')'
285 cpdef uint32_t get_bits(self):
286 return self._c_quire.v
287 bits = property(get_bits)
291 cpdef Quire8 qam(self, Posit8 a1, Posit8 a2):
292 cdef cposit.quire8_t f = cposit.q8_fdp_add(self._c_quire, a1._c_posit, a2._c_posit)
293 return Quire8.from_c_quire(f)
295 cpdef Quire8 qsm(self, Posit8 a1, Posit8 a2):
296 cdef cposit.quire8_t f = cposit.q8_fdp_sub(self._c_quire, a1._c_posit, a2._c_posit)
297 return Quire8.from_c_quire(f)
299 cpdef void iqam(self, Posit8 a1, Posit8 a2):
300 self._c_quire = cposit.q8_fdp_add(self._c_quire, a1._c_posit, a2._c_posit)
302 cpdef void iqsm(self, Posit8 a1, Posit8 a2):
303 self._c_quire = cposit.q8_fdp_sub(self._c_quire, a1._c_posit, a2._c_posit)
305 cpdef void iclr(self):
306 cposit.q8_clr(self._c_quire)
308 # conversion back to posit
310 cpdef Posit8 to_posit(self):
311 cpdef cposit.posit8_t f = cposit.q8_to_p8(self._c_quire)
312 return Posit8.from_c_posit(f)
315 # external, non-method arithmetic
317 cpdef Posit8 p8_neg(Posit8 a1):
318 cdef cposit.posit8_t f = _p8_neg(a1._c_posit)
319 return Posit8.from_c_posit(f)
321 cpdef Posit8 p8_abs(Posit8 a1):
322 cdef cposit.posit8_t f = _p8_abs(a1._c_posit)
323 return Posit8.from_c_posit(f)
325 cpdef Posit8 p8_round(Posit8 a1):
326 cdef cposit.posit8_t f = cposit.p8_roundToInt(a1._c_posit)
327 return Posit8.from_c_posit(f)
329 cpdef Posit8 p8_add(Posit8 a1, Posit8 a2):
330 cdef cposit.posit8_t f = cposit.p8_add(a1._c_posit, a2._c_posit)
331 return Posit8.from_c_posit(f)
333 cpdef Posit8 p8_sub(Posit8 a1, Posit8 a2):
334 cdef cposit.posit8_t f = cposit.p8_sub(a1._c_posit, a2._c_posit)
335 return Posit8.from_c_posit(f)
337 cpdef Posit8 p8_mul(Posit8 a1, Posit8 a2):
338 cdef cposit.posit8_t f = cposit.p8_mul(a1._c_posit, a2._c_posit)
339 return Posit8.from_c_posit(f)
341 cpdef Posit8 p8_fma(Posit8 a1, Posit8 a2, Posit8 a3):
342 cdef cposit.posit8_t f = cposit.p8_mulAdd(a1._c_posit, a2._c_posit, a3._c_posit)
343 return Posit8.from_c_posit(f)
345 cpdef Posit8 p8_fam(Posit8 a3, Posit8 a1, Posit8 a2):
346 cdef cposit.posit8_t f = cposit.p8_mulAdd(a1._c_posit, a2._c_posit, a3._c_posit)
347 return Posit8.from_c_posit(f)
349 cpdef Posit8 p8_div(Posit8 a1, Posit8 a2):
350 cdef cposit.posit8_t f = cposit.p8_div(a1._c_posit, a2._c_posit)
351 return Posit8.from_c_posit(f)
353 cpdef Posit8 p8_sqrt(Posit8 a1):
354 cdef cposit.posit8_t f = cposit.p8_sqrt(a1._c_posit)
355 return Posit8.from_c_posit(f)
357 cpdef bint p8_eq(Posit8 a1, Posit8 a2):
358 return cposit.p8_eq(a1._c_posit, a2._c_posit)
360 cpdef bint p8_le(Posit8 a1, Posit8 a2):
361 return cposit.p8_le(a1._c_posit, a2._c_posit)
363 cpdef bint p8_lt(Posit8 a1, Posit8 a2):
364 return cposit.p8_lt(a1._c_posit, a2._c_posit)
366 cpdef Posit16 p8_to_p16(Posit8 a1):
367 cdef cposit.posit16_t f = cposit.p8_to_p16(a1._c_posit)
368 return Posit16.from_c_posit(f)
370 cpdef Quire8 p8_to_q8(Posit8 a1):
371 cdef cposit.quire8_t f
373 f = cposit.q8_fdp_add(f, a1._c_posit, _p8_one)
374 return Quire8.from_c_quire(f)
376 cpdef Quire8 q8_qam(Quire8 a3, Posit8 a1, Posit8 a2):
377 cdef cposit.quire8_t f = cposit.q8_fdp_add(a3._c_quire, a1._c_posit, a2._c_posit)
378 return Quire8.from_c_quire(f)
380 cpdef Quire8 q8_qsm(Quire8 a3, Posit8 a1, Posit8 a2):
381 cdef cposit.quire8_t f = cposit.q8_fdp_sub(a3._c_quire, a1._c_posit, a2._c_posit)
382 return Quire8.from_c_quire(f)
384 cpdef Posit8 q8_to_p8(Quire8 a1):
385 cpdef cposit.posit8_t f = cposit.q8_to_p8(a1._c_quire)
386 return Posit8.from_c_posit(f)
391 # the wrapped posit value
392 cdef cposit.posit16_t _c_posit
394 # factory function constructors that bypass __init__
397 cdef Posit16 from_c_posit(cposit.posit16_t f):
398 """Factory function to create a Posit16 object directly from
401 cdef Posit16 obj = Posit16.__new__(Posit16)
406 def from_bits(uint16_t value):
407 """Factory function to create a Posit16 object from a bit pattern
408 represented as an integer.
410 cdef Posit16 obj = Posit16.__new__(Posit16)
411 obj._c_posit.v = value
415 def from_double(double value):
416 """Factory function to create a Posit16 object from a double.
418 cdef Posit16 obj = Posit16.__new__(Posit16)
419 obj._c_posit = cposit.convertDoubleToP16(value)
422 # convenience interface for use inside Python
424 def __init__(self, value):
425 if isinstance(value, int):
426 self._c_posit.v = value
429 self._c_posit = cposit.convertDoubleToP16(f)
432 return cposit.convertP16ToDouble(self._c_posit)
435 return int(cposit.convertP16ToDouble(self._c_posit))
438 return repr(cposit.convertP16ToDouble(self._c_posit))
441 return 'Posit16(' + repr(cposit.convertP16ToDouble(self._c_posit)) + ')'
443 cpdef uint16_t get_bits(self):
444 return self._c_posit.v
445 bits = property(get_bits)
449 cpdef Posit16 neg(self):
450 cdef cposit.posit16_t f = _p16_neg(self._c_posit)
451 return Posit16.from_c_posit(f)
456 cpdef Posit16 abs(self):
457 cdef cposit.posit16_t f = _p16_abs(self._c_posit)
458 return Posit16.from_c_posit(f)
463 cpdef Posit16 round(self):
464 cdef cposit.posit16_t f = cposit.p16_roundToInt(self._c_posit)
465 return Posit16.from_c_posit(f)
470 cpdef Posit16 add(self, Posit16 other):
471 cdef cposit.posit16_t f = cposit.p16_add(self._c_posit, other._c_posit)
472 return Posit16.from_c_posit(f)
474 def __add__(self, Posit16 other):
475 return self.add(other)
477 cpdef Posit16 sub(self, Posit16 other):
478 cdef cposit.posit16_t f = cposit.p16_sub(self._c_posit, other._c_posit)
479 return Posit16.from_c_posit(f)
481 def __sub__(self, Posit16 other):
482 return self.sub(other)
484 cpdef Posit16 mul(self, Posit16 other):
485 cdef cposit.posit16_t f = cposit.p16_mul(self._c_posit, other._c_posit)
486 return Posit16.from_c_posit(f)
488 def __mul__(self, Posit16 other):
489 return self.mul(other)
491 cpdef Posit16 fma(self, Posit16 a2, Posit16 a3):
492 cdef cposit.posit16_t f = cposit.p16_mulAdd(self._c_posit, a2._c_posit, a3._c_posit)
493 return Posit16.from_c_posit(f)
495 cpdef Posit16 fam(self, Posit16 a1, Posit16 a2):
496 cdef cposit.posit16_t f = cposit.p16_mulAdd(a1._c_posit, a2._c_posit, self._c_posit)
497 return Posit16.from_c_posit(f)
499 cpdef Posit16 div(self, Posit16 other):
500 cdef cposit.posit16_t f = cposit.p16_div(self._c_posit, other._c_posit)
501 return Posit16.from_c_posit(f)
503 def __truediv__(self, Posit16 other):
504 return self.div(other)
506 cpdef Posit16 sqrt(self):
507 cdef cposit.posit16_t f = cposit.p16_sqrt(self._c_posit)
508 return Posit16.from_c_posit(f)
510 # in-place arithmetic
512 cpdef void ineg(self):
513 self._c_posit = _p16_neg(self._c_posit)
515 cpdef void iabs(self):
516 self._c_posit = _p16_abs(self._c_posit)
518 cpdef void iround(self):
519 self._c_posit = cposit.p16_roundToInt(self._c_posit)
521 cpdef void iadd(self, Posit16 other):
522 self._c_posit = cposit.p16_add(self._c_posit, other._c_posit)
524 def __iadd__(self, Posit16 other):
528 cpdef void isub(self, Posit16 other):
529 self._c_posit = cposit.p16_sub(self._c_posit, other._c_posit)
531 def __isub__(self, Posit16 other):
535 cpdef void imul(self, Posit16 other):
536 self._c_posit = cposit.p16_mul(self._c_posit, other._c_posit)
538 def __imul__(self, Posit16 other):
542 cpdef void ifma(self, Posit16 a2, Posit16 a3):
543 self._c_posit = cposit.p16_mulAdd(self._c_posit, a2._c_posit, a3._c_posit)
545 cpdef void ifam(self, Posit16 a1, Posit16 a2):
546 self._c_posit = cposit.p16_mulAdd(a1._c_posit, a2._c_posit, self._c_posit)
548 cpdef void idiv(self, Posit16 other):
549 self._c_posit = cposit.p16_div(self._c_posit, other._c_posit)
551 def __itruediv__(self, Posit16 other):
555 cpdef void isqrt(self):
556 self._c_posit = cposit.p16_sqrt(self._c_posit)
560 cpdef bint eq(self, Posit16 other):
561 return cposit.p16_eq(self._c_posit, other._c_posit)
563 cpdef bint le(self, Posit16 other):
564 return cposit.p16_le(self._c_posit, other._c_posit)
566 cpdef bint lt(self, Posit16 other):
567 return cposit.p16_lt(self._c_posit, other._c_posit)
569 def __lt__(self, Posit16 other):
570 return self.lt(other)
572 def __le__(self, Posit16 other):
573 return self.le(other)
575 def __eq__(self, Posit16 other):
576 return self.eq(other)
578 def __ne__(self, Posit16 other):
579 return not self.eq(other)
581 def __ge__(self, Posit16 other):
582 return other.le(self)
584 def __gt__(self, Posit16 other):
585 return other.lt(self)
587 # conversion to other posit types
590 cdef cposit.posit8_t f = cposit.p16_to_p8(self._c_posit)
591 return Posit8.from_c_posit(f)
593 cpdef to_quire(self):
594 cdef cposit.quire16_t f
596 f = cposit.q16_fdp_add(f, self._c_posit, _p16_one)
597 return Quire16.from_c_quire(f)
602 # the wrapped quire value
603 cdef cposit.quire16_t _c_quire
605 # factory function constructors that bypass init
608 cdef Quire16 from_c_quire(cposit.quire16_t f):
609 """Factory function to create a Quire16 object directly from
612 cdef Quire16 obj = Quire16.__new__(Quire16)
617 def from_bits(value):
618 """Factory function to create a Quire16 object from a bit pattern
619 represented as an integer.
621 cdef Quire16 obj = Quire16.__new__(Quire16)
623 if not isinstance(value, int):
624 raise TypeError('expecting int, got {}'.format(repr(value)))
626 for idx in range(1, -1, -1):
627 obj._c_quire.v[idx] = value & 0xffffffffffffffff
631 raise OverflowError('value too large to fit in uint64_t[2]')
635 # convenience interface for use inside Python
637 def __init__(self, value):
638 if isinstance(value, int):
639 for idx in range(1, -1, -1):
640 self._c_quire.v[idx] = value & 0xffffffffffffffff
643 raise OverflowError('value too large to fit in uint64_t[2]')
646 cposit.q16_clr(self._c_quire)
647 self._c_quire = cposit.q16_fdp_add(self._c_quire, cposit.convertDoubleToP16(f), _p16_one)
650 return cposit.convertP16ToDouble(cposit.q16_to_p16(self._c_quire))
653 return int(cposit.convertP16ToDouble(cposit.q16_to_p16(self._c_quire)))
656 return repr(cposit.convertP16ToDouble(cposit.q16_to_p16(self._c_quire)))
659 return 'Quire16(' + repr(cposit.convertP16ToDouble(cposit.q16_to_p16(self._c_quire))) + ')'
663 for u in self._c_quire.v:
667 bits = property(get_bits)
671 cpdef Quire16 qam(self, Posit16 a1, Posit16 a2):
672 cdef cposit.quire16_t f = cposit.q16_fdp_add(self._c_quire, a1._c_posit, a2._c_posit)
673 return Quire16.from_c_quire(f)
675 cpdef Quire16 qsm(self, Posit16 a1, Posit16 a2):
676 cdef cposit.quire16_t f = cposit.q16_fdp_sub(self._c_quire, a1._c_posit, a2._c_posit)
677 return Quire16.from_c_quire(f)
679 cpdef void iqam(self, Posit16 a1, Posit16 a2):
680 self._c_quire = cposit.q16_fdp_add(self._c_quire, a1._c_posit, a2._c_posit)
682 cpdef void iqsm(self, Posit16 a1, Posit16 a2):
683 self._c_quire = cposit.q16_fdp_sub(self._c_quire, a1._c_posit, a2._c_posit)
685 cpdef void iclr(self):
686 cposit.q16_clr(self._c_quire)
688 # conversion back to posit
690 cpdef Posit16 to_posit(self):
691 cpdef cposit.posit16_t f = cposit.q16_to_p16(self._c_quire)
692 return Posit16.from_c_posit(f)
695 # external, non-method arithmetic
697 cpdef Posit16 p16_neg(Posit16 a1):
698 cdef cposit.posit16_t f = _p16_neg(a1._c_posit)
699 return Posit16.from_c_posit(f)
701 cpdef Posit16 p16_abs(Posit16 a1):
702 cdef cposit.posit16_t f = _p16_abs(a1._c_posit)
703 return Posit16.from_c_posit(f)
705 cpdef Posit16 p16_round(Posit16 a1):
706 cdef cposit.posit16_t f = cposit.p16_roundToInt(a1._c_posit)
707 return Posit16.from_c_posit(f)
709 cpdef Posit16 p16_add(Posit16 a1, Posit16 a2):
710 cdef cposit.posit16_t f = cposit.p16_add(a1._c_posit, a2._c_posit)
711 return Posit16.from_c_posit(f)
713 cpdef Posit16 p16_sub(Posit16 a1, Posit16 a2):
714 cdef cposit.posit16_t f = cposit.p16_sub(a1._c_posit, a2._c_posit)
715 return Posit16.from_c_posit(f)
717 cpdef Posit16 p16_mul(Posit16 a1, Posit16 a2):
718 cdef cposit.posit16_t f = cposit.p16_mul(a1._c_posit, a2._c_posit)
719 return Posit16.from_c_posit(f)
721 cpdef Posit16 p16_fma(Posit16 a1, Posit16 a2, Posit16 a3):
722 cdef cposit.posit16_t f = cposit.p16_mulAdd(a1._c_posit, a2._c_posit, a3._c_posit)
723 return Posit16.from_c_posit(f)
725 cpdef Posit16 p16_fam(Posit16 a3, Posit16 a1, Posit16 a2):
726 cdef cposit.posit16_t f = cposit.p16_mulAdd(a1._c_posit, a2._c_posit, a3._c_posit)
727 return Posit16.from_c_posit(f)
729 cpdef Posit16 p16_div(Posit16 a1, Posit16 a2):
730 cdef cposit.posit16_t f = cposit.p16_div(a1._c_posit, a2._c_posit)
731 return Posit16.from_c_posit(f)
733 cpdef Posit16 p16_sqrt(Posit16 a1):
734 cdef cposit.posit16_t f = cposit.p16_sqrt(a1._c_posit)
735 return Posit16.from_c_posit(f)
737 cpdef bint p16_eq(Posit16 a1, Posit16 a2):
738 return cposit.p16_eq(a1._c_posit, a2._c_posit)
740 cpdef bint p16_le(Posit16 a1, Posit16 a2):
741 return cposit.p16_le(a1._c_posit, a2._c_posit)
743 cpdef bint p16_lt(Posit16 a1, Posit16 a2):
744 return cposit.p16_lt(a1._c_posit, a2._c_posit)
746 cpdef Posit8 p16_to_p8(Posit16 a1):
747 cdef cposit.posit8_t f = cposit.p16_to_p8(a1._c_posit)
748 return Posit8.from_c_posit(f)
750 cpdef Quire16 p16_to_q16(Posit16 a1):
751 cdef cposit.quire16_t f
753 f = cposit.q16_fdp_add(f, a1._c_posit, _p16_one)
754 return Quire16.from_c_quire(f)
756 cpdef Quire16 q16_qam(Quire16 a3, Posit16 a1, Posit16 a2):
757 cdef cposit.quire16_t f = cposit.q16_fdp_add(a3._c_quire, a1._c_posit, a2._c_posit)
758 return Quire16.from_c_quire(f)
760 cpdef Quire16 q16_qsm(Quire16 a3, Posit16 a1, Posit16 a2):
761 cdef cposit.quire16_t f = cposit.q16_fdp_sub(a3._c_quire, a1._c_posit, a2._c_posit)
762 return Quire16.from_c_quire(f)
764 cpdef Posit16 q16_to_p16(Quire16 a1):
765 cpdef cposit.posit16_t f = cposit.q16_to_p16(a1._c_quire)
766 return Posit16.from_c_posit(f)