Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/math/quaternion.hpp @ 101:c530137014c0
Update Boost headers (1.58.0)
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:12:49 +0100 |
parents | 2665513ce2d3 |
children |
comparison
equal
deleted
inserted
replaced
100:793467b5e61c | 101:c530137014c0 |
---|---|
31 | 31 |
32 namespace boost | 32 namespace boost |
33 { | 33 { |
34 namespace math | 34 namespace math |
35 { | 35 { |
36 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
37 // gcc 2.95.x uses expression templates for valarray calculations, but | |
38 // the result is not conforming. We need BOOST_GET_VALARRAY to get an | |
39 // actual valarray result when we need to call a member function | |
40 #define BOOST_GET_VALARRAY(T,x) ::std::valarray<T>(x) | |
41 // gcc 2.95.x has an "std::ios" class that is similar to | |
42 // "std::ios_base", so we just use a #define | |
43 #define BOOST_IOS_BASE ::std::ios | |
44 // gcc 2.x ignores function scope using declarations, | |
45 // put them in the scope of the enclosing namespace instead: | |
46 using ::std::valarray; | |
47 using ::std::sqrt; | |
48 using ::std::cos; | |
49 using ::std::sin; | |
50 using ::std::exp; | |
51 using ::std::cosh; | |
52 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
53 | 36 |
54 #define BOOST_QUATERNION_ACCESSOR_GENERATOR(type) \ | 37 #define BOOST_QUATERNION_ACCESSOR_GENERATOR(type) \ |
55 type real() const \ | 38 type real() const \ |
56 { \ | 39 { \ |
57 return(a); \ | 40 return(a); \ |
599 d /= rhs; \ | 582 d /= rhs; \ |
600 \ | 583 \ |
601 return(*this); \ | 584 return(*this); \ |
602 } | 585 } |
603 | 586 |
604 #if defined(__GNUC__) && (__GNUC__ < 3) | 587 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) |
605 #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_2(type) \ | |
606 quaternion<type> & operator /= (::std::complex<type> const & rhs) \ | |
607 { \ | |
608 using ::std::valarray; \ | |
609 \ | |
610 valarray<type> tr(2); \ | |
611 \ | |
612 tr[0] = rhs.real(); \ | |
613 tr[1] = rhs.imag(); \ | |
614 \ | |
615 type mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)(); \ | |
616 \ | |
617 tr *= mixam; \ | |
618 \ | |
619 valarray<type> tt(4); \ | |
620 \ | |
621 tt[0] = +a*tr[0]+b*tr[1]; \ | |
622 tt[1] = -a*tr[1]+b*tr[0]; \ | |
623 tt[2] = +c*tr[0]-d*tr[1]; \ | |
624 tt[3] = +c*tr[1]+d*tr[0]; \ | |
625 \ | |
626 tr *= tr; \ | |
627 \ | |
628 tt *= (mixam/tr.sum()); \ | |
629 \ | |
630 a = tt[0]; \ | |
631 b = tt[1]; \ | |
632 c = tt[2]; \ | |
633 d = tt[3]; \ | |
634 \ | |
635 return(*this); \ | |
636 } | |
637 #elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) | |
638 #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_2(type) \ | 588 #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_2(type) \ |
639 quaternion<type> & operator /= (::std::complex<type> const & rhs) \ | 589 quaternion<type> & operator /= (::std::complex<type> const & rhs) \ |
640 { \ | 590 { \ |
641 using ::std::valarray; \ | 591 using ::std::valarray; \ |
642 using ::std::abs; \ | 592 using ::std::abs; \ |
699 c = tt[2]; \ | 649 c = tt[2]; \ |
700 d = tt[3]; \ | 650 d = tt[3]; \ |
701 \ | 651 \ |
702 return(*this); \ | 652 return(*this); \ |
703 } | 653 } |
704 #endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ | 654 #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ |
705 | 655 |
706 #if defined(__GNUC__) && (__GNUC__ < 3) | 656 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) |
707 #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_3(type) \ | |
708 template<typename X> \ | |
709 quaternion<type> & operator /= (quaternion<X> const & rhs) \ | |
710 { \ | |
711 using ::std::valarray; \ | |
712 \ | |
713 valarray<type> tr(4); \ | |
714 \ | |
715 tr[0] = static_cast<type>(rhs.R_component_1()); \ | |
716 tr[1] = static_cast<type>(rhs.R_component_2()); \ | |
717 tr[2] = static_cast<type>(rhs.R_component_3()); \ | |
718 tr[3] = static_cast<type>(rhs.R_component_4()); \ | |
719 \ | |
720 type mixam = (BOOST_GET_VALARRAY(type,static_cast<type>(1)/abs(tr)).max)(); \ | |
721 \ | |
722 tr *= mixam; \ | |
723 \ | |
724 valarray<type> tt(4); \ | |
725 \ | |
726 tt[0] = +a*tr[0]+b*tr[1]+c*tr[2]+d*tr[3]; \ | |
727 tt[1] = -a*tr[1]+b*tr[0]-c*tr[3]+d*tr[2]; \ | |
728 tt[2] = -a*tr[2]+b*tr[3]+c*tr[0]-d*tr[1]; \ | |
729 tt[3] = -a*tr[3]-b*tr[2]+c*tr[1]+d*tr[0]; \ | |
730 \ | |
731 tr *= tr; \ | |
732 \ | |
733 tt *= (mixam/tr.sum()); \ | |
734 \ | |
735 a = tt[0]; \ | |
736 b = tt[1]; \ | |
737 c = tt[2]; \ | |
738 d = tt[3]; \ | |
739 \ | |
740 return(*this); \ | |
741 } | |
742 #elif defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) | |
743 #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_3(type) \ | 657 #define BOOST_QUATERNION_MEMBER_DIV_GENERATOR_3(type) \ |
744 template<typename X> \ | 658 template<typename X> \ |
745 quaternion<type> & operator /= (quaternion<X> const & rhs) \ | 659 quaternion<type> & operator /= (quaternion<X> const & rhs) \ |
746 { \ | 660 { \ |
747 using ::std::valarray; \ | 661 using ::std::valarray; \ |
810 c = tt[2]; \ | 724 c = tt[2]; \ |
811 d = tt[3]; \ | 725 d = tt[3]; \ |
812 \ | 726 \ |
813 return(*this); \ | 727 return(*this); \ |
814 } | 728 } |
815 #endif /* defined(__GNUC__) && (__GNUC__ < 3) */ /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ | 729 #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ |
816 | 730 |
817 #define BOOST_QUATERNION_MEMBER_ADD_GENERATOR(type) \ | 731 #define BOOST_QUATERNION_MEMBER_ADD_GENERATOR(type) \ |
818 BOOST_QUATERNION_MEMBER_ADD_GENERATOR_1(type) \ | 732 BOOST_QUATERNION_MEMBER_ADD_GENERATOR_1(type) \ |
819 BOOST_QUATERNION_MEMBER_ADD_GENERATOR_2(type) \ | 733 BOOST_QUATERNION_MEMBER_ADD_GENERATOR_2(type) \ |
820 BOOST_QUATERNION_MEMBER_ADD_GENERATOR_3(type) | 734 BOOST_QUATERNION_MEMBER_ADD_GENERATOR_3(type) |
1217 | 1131 |
1218 // Note: we allow the following formats, whith a, b, c, and d reals | 1132 // Note: we allow the following formats, whith a, b, c, and d reals |
1219 // a | 1133 // a |
1220 // (a), (a,b), (a,b,c), (a,b,c,d) | 1134 // (a), (a,b), (a,b,c), (a,b,c,d) |
1221 // (a,(c)), (a,(c,d)), ((a)), ((a),c), ((a),(c)), ((a),(c,d)), ((a,b)), ((a,b),c), ((a,b),(c)), ((a,b),(c,d)) | 1135 // (a,(c)), (a,(c,d)), ((a)), ((a),c), ((a),(c)), ((a),(c,d)), ((a,b)), ((a,b),c), ((a,b),(c)), ((a,b),(c,d)) |
1222 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1223 template<typename T> | |
1224 std::istream & operator >> ( ::std::istream & is, | |
1225 quaternion<T> & q) | |
1226 #else | |
1227 template<typename T, typename charT, class traits> | 1136 template<typename T, typename charT, class traits> |
1228 ::std::basic_istream<charT,traits> & operator >> ( ::std::basic_istream<charT,traits> & is, | 1137 ::std::basic_istream<charT,traits> & operator >> ( ::std::basic_istream<charT,traits> & is, |
1229 quaternion<T> & q) | 1138 quaternion<T> & q) |
1230 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | 1139 { |
1231 { | |
1232 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1233 typedef char charT; | |
1234 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
1235 | 1140 |
1236 #ifdef BOOST_NO_STD_LOCALE | 1141 #ifdef BOOST_NO_STD_LOCALE |
1237 #else | 1142 #else |
1238 const ::std::ctype<charT> & ct = ::std::use_facet< ::std::ctype<charT> >(is.getloc()); | 1143 const ::std::ctype<charT> & ct = ::std::use_facet< ::std::ctype<charT> >(is.getloc()); |
1239 #endif /* BOOST_NO_STD_LOCALE */ | 1144 #endif /* BOOST_NO_STD_LOCALE */ |
1317 { | 1222 { |
1318 q = quaternion<T>(a,b,c,d); | 1223 q = quaternion<T>(a,b,c,d); |
1319 } | 1224 } |
1320 else // error | 1225 else // error |
1321 { | 1226 { |
1322 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1323 is.setstate(::std::ios::failbit); | |
1324 #else | |
1325 is.setstate(::std::ios_base::failbit); | 1227 is.setstate(::std::ios_base::failbit); |
1326 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
1327 } | 1228 } |
1328 } | 1229 } |
1329 else // error | 1230 else // error |
1330 { | 1231 { |
1331 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1332 is.setstate(::std::ios::failbit); | |
1333 #else | |
1334 is.setstate(::std::ios_base::failbit); | 1232 is.setstate(::std::ios_base::failbit); |
1335 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
1336 } | 1233 } |
1337 } | 1234 } |
1338 else // read "(a", possible: (a), (a,b), (a,b,c), (a,b,c,d), (a,(c)), (a,(c,d)) | 1235 else // read "(a", possible: (a), (a,b), (a,b,c), (a,b,c,d), (a,(c)), (a,(c,d)) |
1339 { | 1236 { |
1340 is.putback(ch); | 1237 is.putback(ch); |
1394 { | 1291 { |
1395 q = quaternion<T>(a,b,c,d); | 1292 q = quaternion<T>(a,b,c,d); |
1396 } | 1293 } |
1397 else // error | 1294 else // error |
1398 { | 1295 { |
1399 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1400 is.setstate(::std::ios::failbit); | |
1401 #else | |
1402 is.setstate(::std::ios_base::failbit); | 1296 is.setstate(::std::ios_base::failbit); |
1403 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
1404 } | 1297 } |
1405 } | 1298 } |
1406 else // read "(a,b", possible: (a,b), (a,b,c), (a,b,c,d) | 1299 else // read "(a,b", possible: (a,b), (a,b,c), (a,b,c,d) |
1407 { | 1300 { |
1408 is.putback(ch); | 1301 is.putback(ch); |
1465 { | 1358 { |
1466 q = quaternion<T>(a,b,c,d); | 1359 q = quaternion<T>(a,b,c,d); |
1467 } | 1360 } |
1468 else // error | 1361 else // error |
1469 { | 1362 { |
1470 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1471 is.setstate(::std::ios::failbit); | |
1472 #else | |
1473 is.setstate(::std::ios_base::failbit); | 1363 is.setstate(::std::ios_base::failbit); |
1474 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
1475 } | 1364 } |
1476 } | 1365 } |
1477 else // error | 1366 else // error |
1478 { | 1367 { |
1479 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1480 is.setstate(::std::ios::failbit); | |
1481 #else | |
1482 is.setstate(::std::ios_base::failbit); | 1368 is.setstate(::std::ios_base::failbit); |
1483 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
1484 } | 1369 } |
1485 } | 1370 } |
1486 else // error | 1371 else // error |
1487 { | 1372 { |
1488 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1489 is.setstate(::std::ios::failbit); | |
1490 #else | |
1491 is.setstate(::std::ios_base::failbit); | 1373 is.setstate(::std::ios_base::failbit); |
1492 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
1493 } | 1374 } |
1494 } | 1375 } |
1495 } | 1376 } |
1496 else // error | 1377 else // error |
1497 { | 1378 { |
1498 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1499 is.setstate(::std::ios::failbit); | |
1500 #else | |
1501 is.setstate(::std::ios_base::failbit); | 1379 is.setstate(::std::ios_base::failbit); |
1502 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
1503 } | 1380 } |
1504 } | 1381 } |
1505 } | 1382 } |
1506 else // format: a | 1383 else // format: a |
1507 { | 1384 { |
1517 finish: | 1394 finish: |
1518 return(is); | 1395 return(is); |
1519 } | 1396 } |
1520 | 1397 |
1521 | 1398 |
1522 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1523 template<typename T> | |
1524 ::std::ostream & operator << ( ::std::ostream & os, | |
1525 quaternion<T> const & q) | |
1526 #else | |
1527 template<typename T, typename charT, class traits> | 1399 template<typename T, typename charT, class traits> |
1528 ::std::basic_ostream<charT,traits> & operator << ( ::std::basic_ostream<charT,traits> & os, | 1400 ::std::basic_ostream<charT,traits> & operator << ( ::std::basic_ostream<charT,traits> & os, |
1529 quaternion<T> const & q) | 1401 quaternion<T> const & q) |
1530 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | 1402 { |
1531 { | |
1532 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1533 ::std::ostringstream s; | |
1534 #else | |
1535 ::std::basic_ostringstream<charT,traits> s; | 1403 ::std::basic_ostringstream<charT,traits> s; |
1536 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | 1404 |
1537 | |
1538 s.flags(os.flags()); | 1405 s.flags(os.flags()); |
1539 #ifdef BOOST_NO_STD_LOCALE | 1406 #ifdef BOOST_NO_STD_LOCALE |
1540 #else | 1407 #else |
1541 s.imbue(os.getloc()); | 1408 s.imbue(os.getloc()); |
1542 #endif /* BOOST_NO_STD_LOCALE */ | 1409 #endif /* BOOST_NO_STD_LOCALE */ |
1585 using ::std::abs; | 1452 using ::std::abs; |
1586 #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ | 1453 #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ |
1587 | 1454 |
1588 BOOST_QUATERNION_VALARRAY_LOADER | 1455 BOOST_QUATERNION_VALARRAY_LOADER |
1589 | 1456 |
1590 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1591 return((BOOST_GET_VALARRAY(T, abs(temp)).max)()); | |
1592 #else | |
1593 return((abs(temp).max)()); | 1457 return((abs(temp).max)()); |
1594 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
1595 } | 1458 } |
1596 | 1459 |
1597 | 1460 |
1598 template<typename T> | 1461 template<typename T> |
1599 inline T l1(quaternion<T> const & q) | 1462 inline T l1(quaternion<T> const & q) |
1602 using ::std::abs; | 1465 using ::std::abs; |
1603 #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ | 1466 #endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ |
1604 | 1467 |
1605 BOOST_QUATERNION_VALARRAY_LOADER | 1468 BOOST_QUATERNION_VALARRAY_LOADER |
1606 | 1469 |
1607 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1608 return(BOOST_GET_VALARRAY(T, abs(temp)).sum()); | |
1609 #else | |
1610 return(abs(temp).sum()); | 1470 return(abs(temp).sum()); |
1611 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
1612 } | 1471 } |
1613 | 1472 |
1614 | 1473 |
1615 template<typename T> | 1474 template<typename T> |
1616 inline T abs(quaternion<T> const & q) | 1475 inline T abs(quaternion<T> const & q) |
1621 | 1480 |
1622 using ::std::sqrt; | 1481 using ::std::sqrt; |
1623 | 1482 |
1624 BOOST_QUATERNION_VALARRAY_LOADER | 1483 BOOST_QUATERNION_VALARRAY_LOADER |
1625 | 1484 |
1626 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1627 T maxim = (BOOST_GET_VALARRAY(T, abs(temp)).max)(); // overflow protection | |
1628 #else | |
1629 T maxim = (abs(temp).max)(); // overflow protection | 1485 T maxim = (abs(temp).max)(); // overflow protection |
1630 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
1631 | 1486 |
1632 if (maxim == static_cast<T>(0)) | 1487 if (maxim == static_cast<T>(0)) |
1633 { | 1488 { |
1634 return(maxim); | 1489 return(maxim); |
1635 } | 1490 } |
1913 } | 1768 } |
1914 } | 1769 } |
1915 } | 1770 } |
1916 } | 1771 } |
1917 | 1772 |
1918 | |
1919 #if BOOST_WORKAROUND(__GNUC__, < 3) | |
1920 #undef BOOST_GET_VALARRAY | |
1921 #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ | |
1922 | |
1923 | |
1924 #endif /* BOOST_QUATERNION_HPP */ | 1773 #endif /* BOOST_QUATERNION_HPP */ |