All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Accuracy.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_ACCURACY_H_
23 #define _BLAZE_MATH_ACCURACY_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
31 #include <blaze/util/Limits.h>
32 
33 
34 namespace blaze {
35 
36 //=================================================================================================
37 //
38 // CLASS DEFINITION
39 //
40 //=================================================================================================
41 
42 //*************************************************************************************************
55 template< typename A > // Positive accuracy type
57 {
58  public:
59  //**Type definitions****************************************************************************
60  typedef A PositiveType;
61  //**********************************************************************************************
62 
63  private:
64  //**Constructor*********************************************************************************
67  explicit inline NegativeAccuracy();
68  // No explicitly declared copy constructor.
70  //**********************************************************************************************
71 
72  public:
73  //**Destructor**********************************************************************************
74  // No explicitly declared destructor.
75  //**********************************************************************************************
76 
77  //**Unary plus/minus operators******************************************************************
80  inline const NegativeAccuracy& operator+() const;
81  inline const PositiveType operator-() const;
83  //**********************************************************************************************
84 
85  //**Conversion operator*************************************************************************
88  template< typename T >
89  inline operator const T() const;
91  //**********************************************************************************************
92 
93  private:
94  //**Forbidden operations************************************************************************
98  void* operator&() const;
99 
100  //**********************************************************************************************
101 
102  //**Friend declarations*************************************************************************
104  friend class Accuracy;
106  //**********************************************************************************************
107 };
108 //*************************************************************************************************
109 
110 
111 
112 
113 //=================================================================================================
114 //
115 // CONSTRUCTOR
116 //
117 //=================================================================================================
118 
119 //*************************************************************************************************
122 template< typename A > // Positive accuracy type
124 {}
125 //*************************************************************************************************
126 
127 
128 
129 
130 //=================================================================================================
131 //
132 // UNARY PLUS/MINUS OPERATORS
133 //
134 //=================================================================================================
135 
136 //*************************************************************************************************
141 template< typename A > // Positive accuracy type
143 {
144  return *this;
145 }
146 //*************************************************************************************************
147 
148 
149 //*************************************************************************************************
154 template< typename A > // Positive accuracy type
156 {
157  return PositiveType();
158 }
159 //*************************************************************************************************
160 
161 
162 
163 
164 //=================================================================================================
165 //
166 // CONVERSION OPERATOR
167 //
168 //=================================================================================================
169 
170 //*************************************************************************************************
176 template< typename A > // Positive accuracy type
177 template< typename T > // Floating point data type
178 inline NegativeAccuracy<A>::operator const T() const
179 {
181  return -Limits<T>::accuracy();
182 }
183 //*************************************************************************************************
184 
185 
186 
187 
188 //=================================================================================================
189 //
190 // GLOBAL OPERATORS
191 //
192 //=================================================================================================
193 
194 //*************************************************************************************************
197 template< typename A, typename T >
198 inline bool operator==( const NegativeAccuracy<A>& lhs, const T& rhs );
199 
200 template< typename A, typename T >
201 inline bool operator==( const T& lhs, const NegativeAccuracy<A>& rhs );
202 
203 template< typename A, typename T >
204 inline bool operator!=( const NegativeAccuracy<A>& lhs, const T& rhs );
205 
206 template< typename A, typename T >
207 inline bool operator!=( const T& lhs, const NegativeAccuracy<A>& rhs );
208 
209 template< typename A, typename T >
210 inline bool operator<( const NegativeAccuracy<A>& lhs, const T& rhs );
211 
212 template< typename A, typename T >
213 inline bool operator<( const T& lhs, const NegativeAccuracy<A>& rhs );
214 
215 template< typename A, typename T >
216 inline bool operator>( const NegativeAccuracy<A>& lhs, const T& rhs );
217 
218 template< typename A, typename T >
219 inline bool operator>( const T& lhs, const NegativeAccuracy<A>& rhs );
221 //*************************************************************************************************
222 
223 
224 //*************************************************************************************************
234 template< typename A // Positive accuracy type
235  , typename T > // Floating point data type
236 inline bool operator==( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
237 {
239  return -Limits<T>::accuracy() == rhs;
240 }
241 //*************************************************************************************************
242 
243 
244 //*************************************************************************************************
254 template< typename A // Positive accuracy type
255  , typename T > // Floating point data type
256 inline bool operator==( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
257 {
259  return lhs == -Limits<T>::accuracy();
260 }
261 //*************************************************************************************************
262 
263 
264 //*************************************************************************************************
274 template< typename A // Positive accuracy type
275  , typename T > // Floating point data type
276 inline bool operator!=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
277 {
279  return -Limits<T>::accuracy() != rhs;
280 }
281 //*************************************************************************************************
282 
283 
284 //*************************************************************************************************
294 template< typename A // Positive accuracy type
295  , typename T > // Floating point data type
296 inline bool operator!=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
297 {
299  return lhs != -Limits<T>::accuracy();
300 }
301 //*************************************************************************************************
302 
303 
304 //*************************************************************************************************
313 template< typename A // Positive accuracy type
314  , typename T > // Floating point data type
315 inline bool operator<( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
316 {
318  return -Limits<T>::accuracy() < rhs;
319 }
320 //*************************************************************************************************
321 
322 
323 //*************************************************************************************************
332 template< typename A // Positive accuracy type
333  , typename T > // Floating point data type
334 inline bool operator<( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
335 {
337  return lhs < -Limits<T>::accuracy();
338 }
339 //*************************************************************************************************
340 
341 
342 //*************************************************************************************************
351 template< typename A // Positive accuracy type
352  , typename T > // Floating point data type
353 inline bool operator>( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
354 {
356  return -Limits<T>::accuracy() > rhs;
357 }
358 //*************************************************************************************************
359 
360 
361 //*************************************************************************************************
370 template< typename A // Positive accuracy type
371  , typename T > // Floating point data type
372 inline bool operator>( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
373 {
375  return lhs > -Limits<T>::accuracy();
376 }
377 //*************************************************************************************************
378 
379 
380 //*************************************************************************************************
389 template< typename A // Positive accuracy type
390  , typename T > // Floating point data type
391 inline bool operator<=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
392 {
394  return -Limits<T>::accuracy() <= rhs;
395 }
396 //*************************************************************************************************
397 
398 
399 //*************************************************************************************************
408 template< typename A // Positive accuracy type
409  , typename T > // Floating point data type
410 inline bool operator<=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
411 {
413  return lhs <= -Limits<T>::accuracy();
414 }
415 //*************************************************************************************************
416 
417 
418 //*************************************************************************************************
427 template< typename A // Positive accuracy type
428  , typename T > // Floating point data type
429 inline bool operator>=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
430 {
432  return -Limits<T>::accuracy() >= rhs;
433 }
434 //*************************************************************************************************
435 
436 
437 //*************************************************************************************************
446 template< typename A // Positive accuracy type
447  , typename T > // Floating point data type
448 inline bool operator>=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
449 {
451  return lhs >= -Limits<T>::accuracy();
452 }
453 //*************************************************************************************************
454 
455 
456 
457 
458 
459 
460 
461 
462 //=================================================================================================
463 //
464 // CLASS DEFINITION
465 //
466 //=================================================================================================
467 
468 //*************************************************************************************************
484 class Accuracy
485 {
486  public:
487  //**Type definitions****************************************************************************
489  //**********************************************************************************************
490 
491  //**Constructor*********************************************************************************
494  explicit inline Accuracy();
495  // No explicitly declared copy constructor.
497  //**********************************************************************************************
498 
499  //**Destructor**********************************************************************************
500  // No explicitly declared destructor.
501  //**********************************************************************************************
502 
503  //**Unary plus/minus operators******************************************************************
506  inline const Accuracy& operator+() const;
507  inline const NegativeType operator-() const;
509  //**********************************************************************************************
510 
511  //**Conversion operator*************************************************************************
514  template< typename T >
515  inline operator const T() const;
517  //**********************************************************************************************
518 
519  private:
520  //**Forbidden operations************************************************************************
523  Accuracy& operator=( const Accuracy& );
524  void* operator&() const;
525 
526  //**********************************************************************************************
527 };
528 //*************************************************************************************************
529 
530 
531 
532 
533 //=================================================================================================
534 //
535 // CONSTRUCTOR
536 //
537 //=================================================================================================
538 
539 //*************************************************************************************************
543 {}
544 //*************************************************************************************************
545 
546 
547 
548 
549 //=================================================================================================
550 //
551 // UNARY PLUS/MINUS OPERATORS
552 //
553 //=================================================================================================
554 
555 //*************************************************************************************************
560 inline const Accuracy& Accuracy::operator+() const
561 {
562  return *this;
563 }
564 //*************************************************************************************************
565 
566 
567 //*************************************************************************************************
573 {
574  return NegativeType();
575 }
576 //*************************************************************************************************
577 
578 
579 
580 
581 //=================================================================================================
582 //
583 // CONVERSION OPERATOR
584 //
585 //=================================================================================================
586 
587 //*************************************************************************************************
593 template< typename T > // Floating point data type
594 inline Accuracy::operator const T() const
595 {
597  return Limits<T>::accuracy();
598 }
599 //*************************************************************************************************
600 
601 
602 
603 
604 //=================================================================================================
605 //
606 // GLOBAL OPERATORS
607 //
608 //=================================================================================================
609 
610 //*************************************************************************************************
613 template< typename T >
614 inline bool operator==( const Accuracy& lhs, const T& rhs );
615 
616 template< typename T >
617 inline bool operator==( const T& lhs, const Accuracy& rhs );
618 
619 template< typename T >
620 inline bool operator!=( const Accuracy& lhs, const T& rhs );
621 
622 template< typename T >
623 inline bool operator!=( const T& lhs, const Accuracy& rhs );
624 
625 template< typename T >
626 inline bool operator<( const Accuracy& lhs, const T& rhs );
627 
628 template< typename T >
629 inline bool operator<( const T& lhs, const Accuracy& rhs );
630 
631 template< typename T >
632 inline bool operator>( const Accuracy& lhs, const T& rhs );
633 
634 template< typename T >
635 inline bool operator>( const T& lhs, const Accuracy& rhs );
637 //*************************************************************************************************
638 
639 
640 //*************************************************************************************************
650 template< typename T > // Floating point data type
651 inline bool operator==( const Accuracy& /*lhs*/, const T& rhs )
652 {
654  return Limits<T>::accuracy() == rhs;
655 }
656 //*************************************************************************************************
657 
658 
659 //*************************************************************************************************
669 template< typename T > // Floating point data type
670 inline bool operator==( const T& lhs, const Accuracy& /*rhs*/ )
671 {
673  return lhs == Limits<T>::accuracy();
674 }
675 //*************************************************************************************************
676 
677 
678 //*************************************************************************************************
688 template< typename T > // Floating point data type
689 inline bool operator!=( const Accuracy& /*lhs*/, const T& rhs )
690 {
692  return Limits<T>::accuracy() != rhs;
693 }
694 //*************************************************************************************************
695 
696 
697 //*************************************************************************************************
707 template< typename T > // Floating point data type
708 inline bool operator!=( const T& lhs, const Accuracy& /*rhs*/ )
709 {
711  return lhs != Limits<T>::accuracy();
712 }
713 //*************************************************************************************************
714 
715 
716 //*************************************************************************************************
725 template< typename T > // Floating point data type
726 inline bool operator<( const Accuracy& /*lhs*/, const T& rhs )
727 {
729  return Limits<T>::accuracy() < rhs;
730 }
731 //*************************************************************************************************
732 
733 
734 //*************************************************************************************************
743 template< typename T > // Floating point data type
744 inline bool operator<( const T& lhs, const Accuracy& /*rhs*/ )
745 {
747  return lhs < Limits<T>::accuracy();
748 }
749 //*************************************************************************************************
750 
751 
752 //*************************************************************************************************
761 template< typename T > // Floating point data type
762 inline bool operator>( const Accuracy& /*lhs*/, const T& rhs )
763 {
765  return Limits<T>::accuracy() > rhs;
766 }
767 //*************************************************************************************************
768 
769 
770 //*************************************************************************************************
779 template< typename T > // Floating point data type
780 inline bool operator>( const T& lhs, const Accuracy& /*rhs*/ )
781 {
783  return lhs > Limits<T>::accuracy();
784 }
785 //*************************************************************************************************
786 
787 
788 //*************************************************************************************************
797 template< typename T > // Floating point data type
798 inline bool operator<=( const Accuracy& /*lhs*/, const T& rhs )
799 {
801  return Limits<T>::accuracy() <= rhs;
802 }
803 //*************************************************************************************************
804 
805 
806 //*************************************************************************************************
815 template< typename T > // Floating point data type
816 inline bool operator<=( const T& lhs, const Accuracy& /*rhs*/ )
817 {
820 }
821 //*************************************************************************************************
822 
823 
824 //*************************************************************************************************
833 template< typename T > // Floating point data type
834 inline bool operator>=( const Accuracy& /*lhs*/, const T& rhs )
835 {
837  return Limits<T>::accuracy() >= rhs;
838 }
839 //*************************************************************************************************
840 
841 
842 //*************************************************************************************************
851 template< typename T > // Floating point data type
852 inline bool operator>=( const T& lhs, const Accuracy& /*rhs*/ )
853 {
855  return lhs >= Limits<T>::accuracy();
856 }
857 //*************************************************************************************************
858 
859 
860 
861 
862 //=================================================================================================
863 //
864 // GLOBAL ACCURACY VALUE
865 //
866 //=================================================================================================
867 
868 //*************************************************************************************************
877 //*************************************************************************************************
878 
879 } // namespace blaze
880 
881 #endif