Mercurial > hg > octave-lyh
comparison liboctave/oct-inttypes.h @ 13734:28ddb3150943
Rename signbit to __signbit, until the problem is fixed in gnulib.
* oct-inttypes.h (octave_int_arith_base<T, true>): Rename signbit to
__signbit to avoid problems with gnulib macro.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Thu, 20 Oct 2011 12:54:58 +0100 |
parents | 15eefbd9d4e8 |
children | 72c96de7a403 |
comparison
equal
deleted
inserted
replaced
13733:b1186adb567e | 13734:28ddb3150943 |
---|---|
450 typedef typename query_integer_type<sizeof (T), false>::type UT; | 450 typedef typename query_integer_type<sizeof (T), false>::type UT; |
451 public: | 451 public: |
452 | 452 |
453 // Returns 1 for negative number, 0 otherwise. | 453 // Returns 1 for negative number, 0 otherwise. |
454 static T | 454 static T |
455 signbit (T x) | 455 __signbit (T x) |
456 { | 456 { |
457 #ifdef HAVE_FAST_INT_OPS | 457 #ifdef HAVE_FAST_INT_OPS |
458 return static_cast<UT> (x) >> std::numeric_limits<T>::digits; | 458 return static_cast<UT> (x) >> std::numeric_limits<T>::digits; |
459 #else | 459 #else |
460 return (x < 0) ? 1 : 0; | 460 return (x < 0) ? 1 : 0; |
494 | 494 |
495 static T | 495 static T |
496 signum (T x) | 496 signum (T x) |
497 { | 497 { |
498 // With modest optimizations, this will compile without a jump. | 498 // With modest optimizations, this will compile without a jump. |
499 return ((x > 0) ? 1 : 0) - signbit (x); | 499 return ((x > 0) ? 1 : 0) - __signbit (x); |
500 } | 500 } |
501 | 501 |
502 // FIXME -- we do not have an authority what signed shifts should | 502 // FIXME -- we do not have an authority what signed shifts should |
503 // exactly do, so we define them the easy way. Note that Matlab does | 503 // exactly do, so we define them the easy way. Note that Matlab does |
504 // not define signed shifts. | 504 // not define signed shifts. |
542 // actually return int. | 542 // actually return int. |
543 T u = static_cast<UT> (x) + static_cast<UT> (y); | 543 T u = static_cast<UT> (x) + static_cast<UT> (y); |
544 T ux = u ^ x, uy = u ^ y; | 544 T ux = u ^ x, uy = u ^ y; |
545 if ((ux & uy) < 0) | 545 if ((ux & uy) < 0) |
546 { | 546 { |
547 u = octave_int_base<T>::max_val () + signbit (~u); | 547 u = octave_int_base<T>::max_val () + __signbit (~u); |
548 } | 548 } |
549 return u; | 549 return u; |
550 #else | 550 #else |
551 // We shall carefully avoid anything that may overflow. | 551 // We shall carefully avoid anything that may overflow. |
552 T u; | 552 T u; |
583 // actually return int. | 583 // actually return int. |
584 T u = static_cast<UT> (x) - static_cast<UT> (y); | 584 T u = static_cast<UT> (x) - static_cast<UT> (y); |
585 T ux = u ^ x, uy = u ^ ~y; | 585 T ux = u ^ x, uy = u ^ ~y; |
586 if ((ux & uy) < 0) | 586 if ((ux & uy) < 0) |
587 { | 587 { |
588 u = octave_int_base<T>::max_val () + signbit (~u); | 588 u = octave_int_base<T>::max_val () + __signbit (~u); |
589 } | 589 } |
590 return u; | 590 return u; |
591 #else | 591 #else |
592 // We shall carefully avoid anything that may overflow. | 592 // We shall carefully avoid anything that may overflow. |
593 T u; | 593 T u; |
649 else | 649 else |
650 { | 650 { |
651 z = x / y; | 651 z = x / y; |
652 T w = -octave_int_abs (x % y); // Can't overflow, but std::abs (x) can! | 652 T w = -octave_int_abs (x % y); // Can't overflow, but std::abs (x) can! |
653 if (w <= y - w) | 653 if (w <= y - w) |
654 z -= 1 - (signbit (x) << 1); | 654 z -= 1 - (__signbit (x) << 1); |
655 } | 655 } |
656 } | 656 } |
657 else | 657 else |
658 { | 658 { |
659 z = x / y; | 659 z = x / y; |
661 // std::abs (int64_t). The call to octave_int_abs can't | 661 // std::abs (int64_t). The call to octave_int_abs can't |
662 // overflow, but std::abs (x) can! | 662 // overflow, but std::abs (x) can! |
663 T w = octave_int_abs (x % y); | 663 T w = octave_int_abs (x % y); |
664 | 664 |
665 if (w >= y - w) | 665 if (w >= y - w) |
666 z += 1 - (signbit (x) << 1); | 666 z += 1 - (__signbit (x) << 1); |
667 } | 667 } |
668 return z; | 668 return z; |
669 } | 669 } |
670 | 670 |
671 // Remainder. | 671 // Remainder. |