Mercurial > hg > octave-nkf
comparison liboctave/oct-inttypes.h @ 7789:82be108cc558
First attempt at single precision tyeps
* * *
corrections to qrupdate single precision routines
* * *
prefer demotion to single over promotion to double
* * *
Add single precision support to log2 function
* * *
Trivial PROJECT file update
* * *
Cache optimized hermitian/transpose methods
* * *
Add tests for tranpose/hermitian and ChangeLog entry for new transpose code
author | David Bateman <dbateman@free.fr> |
---|---|
date | Sun, 27 Apr 2008 22:34:17 +0200 |
parents | a89b3fa632ee |
children | 935be827eaf8 |
comparison
equal
deleted
inserted
replaced
7788:45f5faba05a2 | 7789:82be108cc558 |
---|---|
130 | 130 |
131 template <typename T> | 131 template <typename T> |
132 inline T | 132 inline T |
133 octave_int_fit_to_range (const double& x, const T& mn, const T& mx) | 133 octave_int_fit_to_range (const double& x, const T& mn, const T& mx) |
134 { | 134 { |
135 return (lo_ieee_isnan (x) ? 0 : (x > mx ? mx : (x < mn ? mn : static_cast<T> (x)))); | 135 return (__lo_ieee_isnan (x) ? 0 : (x > mx ? mx : (x < mn ? mn : static_cast<T> (x)))); |
136 } | 136 } |
137 | 137 |
138 // If X is unsigned and the new type is signed, then we only have to | 138 // If X is unsigned and the new type is signed, then we only have to |
139 // check the upper limit, but we should cast the maximum value of the | 139 // check the upper limit, but we should cast the maximum value of the |
140 // new type to an unsigned type before performing the comparison. | 140 // new type to an unsigned type before performing the comparison. |
448 octave_int<T> | 448 octave_int<T> |
449 pow (double a, const octave_int<T>& b) | 449 pow (double a, const octave_int<T>& b) |
450 { | 450 { |
451 double tb = static_cast<double> (b.value ()); | 451 double tb = static_cast<double> (b.value ()); |
452 double r = pow (a, tb); | 452 double r = pow (a, tb); |
453 r = lo_ieee_isnan (r) ? 0 : xround (r); | 453 r = __lo_ieee_isnan (r) ? 0 : xround (r); |
454 return OCTAVE_INT_FIT_TO_RANGE (r, T); | 454 return OCTAVE_INT_FIT_TO_RANGE (r, T); |
455 } | 455 } |
456 | 456 |
457 template <class T> | 457 template <class T> |
458 octave_int<T> | 458 octave_int<T> |
459 pow (const octave_int<T>& a, double b) | 459 pow (const octave_int<T>& a, double b) |
460 { | 460 { |
461 double ta = static_cast<double> (a.value ()); | 461 double ta = static_cast<double> (a.value ()); |
462 double r = pow (ta, b); | 462 double r = pow (ta, b); |
463 r = lo_ieee_isnan (r) ? 0 : xround (r); | 463 r = __lo_ieee_isnan (r) ? 0 : xround (r); |
464 return OCTAVE_INT_FIT_TO_RANGE (r, T); | 464 return OCTAVE_INT_FIT_TO_RANGE (r, T); |
465 } | 465 } |
466 | 466 |
467 template <class T> | 467 template <class T> |
468 std::ostream& | 468 std::ostream& |
522 octave_int<T> \ | 522 octave_int<T> \ |
523 operator OP (const octave_int<T>& x, double y) \ | 523 operator OP (const octave_int<T>& x, double y) \ |
524 { \ | 524 { \ |
525 double tx = static_cast<double> (x.value ()); \ | 525 double tx = static_cast<double> (x.value ()); \ |
526 double r = xround (tx OP y); \ | 526 double r = xround (tx OP y); \ |
527 r = lo_ieee_isnan (r) ? 0 : xround (r); \ | 527 r = __lo_ieee_isnan (r) ? 0 : xround (r); \ |
528 return OCTAVE_INT_FIT_TO_RANGE (r, T); \ | 528 return OCTAVE_INT_FIT_TO_RANGE (r, T); \ |
529 } | 529 } |
530 | 530 |
531 OCTAVE_INT_DOUBLE_BIN_OP(+) | 531 OCTAVE_INT_DOUBLE_BIN_OP(+) |
532 OCTAVE_INT_DOUBLE_BIN_OP(-) | 532 OCTAVE_INT_DOUBLE_BIN_OP(-) |
538 octave_int<T> \ | 538 octave_int<T> \ |
539 operator OP (double x, const octave_int<T>& y) \ | 539 operator OP (double x, const octave_int<T>& y) \ |
540 { \ | 540 { \ |
541 double ty = static_cast<double> (y.value ()); \ | 541 double ty = static_cast<double> (y.value ()); \ |
542 double r = x OP ty; \ | 542 double r = x OP ty; \ |
543 r = lo_ieee_isnan (r) ? 0 : xround (r); \ | 543 r = __lo_ieee_isnan (r) ? 0 : xround (r); \ |
544 return OCTAVE_INT_FIT_TO_RANGE (r, T); \ | 544 return OCTAVE_INT_FIT_TO_RANGE (r, T); \ |
545 } | 545 } |
546 | 546 |
547 OCTAVE_DOUBLE_INT_BIN_OP(+) | 547 OCTAVE_DOUBLE_INT_BIN_OP(+) |
548 OCTAVE_DOUBLE_INT_BIN_OP(-) | 548 OCTAVE_DOUBLE_INT_BIN_OP(-) |
578 OCTAVE_DOUBLE_INT_CMP_OP (<=) | 578 OCTAVE_DOUBLE_INT_CMP_OP (<=) |
579 OCTAVE_DOUBLE_INT_CMP_OP (>=) | 579 OCTAVE_DOUBLE_INT_CMP_OP (>=) |
580 OCTAVE_DOUBLE_INT_CMP_OP (>) | 580 OCTAVE_DOUBLE_INT_CMP_OP (>) |
581 OCTAVE_DOUBLE_INT_CMP_OP (==) | 581 OCTAVE_DOUBLE_INT_CMP_OP (==) |
582 OCTAVE_DOUBLE_INT_CMP_OP (!=) | 582 OCTAVE_DOUBLE_INT_CMP_OP (!=) |
583 | |
584 #define OCTAVE_INT_FLOAT_BIN_OP(OP) \ | |
585 template <class T> \ | |
586 octave_int<T> \ | |
587 operator OP (const octave_int<T>& x, float y) \ | |
588 { \ | |
589 double tx = static_cast<double> (x.value ()); \ | |
590 double r = xround (tx OP y); \ | |
591 r = __lo_ieee_isnan (r) ? 0 : xround (r); \ | |
592 return OCTAVE_INT_FIT_TO_RANGE (r, T); \ | |
593 } | |
594 | |
595 OCTAVE_INT_FLOAT_BIN_OP(+) | |
596 OCTAVE_INT_FLOAT_BIN_OP(-) | |
597 OCTAVE_INT_FLOAT_BIN_OP(*) | |
598 OCTAVE_INT_FLOAT_BIN_OP(/) | |
599 | |
600 #define OCTAVE_FLOAT_INT_BIN_OP(OP) \ | |
601 template <class T> \ | |
602 octave_int<T> \ | |
603 operator OP (float x, const octave_int<T>& y) \ | |
604 { \ | |
605 double ty = static_cast<double> (y.value ()); \ | |
606 double r = x OP ty; \ | |
607 r = __lo_ieee_isnan (r) ? 0 : xround (r); \ | |
608 return OCTAVE_INT_FIT_TO_RANGE (r, T); \ | |
609 } | |
610 | |
611 OCTAVE_FLOAT_INT_BIN_OP(+) | |
612 OCTAVE_FLOAT_INT_BIN_OP(-) | |
613 OCTAVE_FLOAT_INT_BIN_OP(*) | |
614 OCTAVE_FLOAT_INT_BIN_OP(/) | |
615 | |
616 #define OCTAVE_INT_FLOAT_CMP_OP(OP) \ | |
617 template <class T> \ | |
618 bool \ | |
619 operator OP (const octave_int<T>& x, const float& y) \ | |
620 { \ | |
621 double tx = static_cast<double> (x.value ()); \ | |
622 return tx OP y; \ | |
623 } | |
624 | |
625 OCTAVE_INT_FLOAT_CMP_OP (<) | |
626 OCTAVE_INT_FLOAT_CMP_OP (<=) | |
627 OCTAVE_INT_FLOAT_CMP_OP (>=) | |
628 OCTAVE_INT_FLOAT_CMP_OP (>) | |
629 OCTAVE_INT_FLOAT_CMP_OP (==) | |
630 OCTAVE_INT_FLOAT_CMP_OP (!=) | |
631 | |
632 #define OCTAVE_FLOAT_INT_CMP_OP(OP) \ | |
633 template <class T> \ | |
634 bool \ | |
635 operator OP (const float& x, const octave_int<T>& y) \ | |
636 { \ | |
637 double ty = static_cast<double> (y.value ()); \ | |
638 return x OP ty; \ | |
639 } | |
640 | |
641 OCTAVE_FLOAT_INT_CMP_OP (<) | |
642 OCTAVE_FLOAT_INT_CMP_OP (<=) | |
643 OCTAVE_FLOAT_INT_CMP_OP (>=) | |
644 OCTAVE_FLOAT_INT_CMP_OP (>) | |
645 OCTAVE_FLOAT_INT_CMP_OP (==) | |
646 OCTAVE_FLOAT_INT_CMP_OP (!=) | |
583 | 647 |
584 #define OCTAVE_INT_BITCMP_OP(OP) \ | 648 #define OCTAVE_INT_BITCMP_OP(OP) \ |
585 template <class T> \ | 649 template <class T> \ |
586 octave_int<T> \ | 650 octave_int<T> \ |
587 operator OP (const octave_int<T>& x, const octave_int<T>& y) \ | 651 operator OP (const octave_int<T>& x, const octave_int<T>& y) \ |