Accuracy.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ACCURACY_H_
36 #define _BLAZE_MATH_ACCURACY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/util/Limits.h>
45 
46 
47 namespace blaze {
48 
49 //=================================================================================================
50 //
51 // CLASS DEFINITION
52 //
53 //=================================================================================================
54 
55 //*************************************************************************************************
68 template< typename A > // Positive accuracy type
70 {
71  public:
72  //**Type definitions****************************************************************************
73  typedef A PositiveType;
74  //**********************************************************************************************
75 
76  private:
77  //**Constructor*********************************************************************************
80  explicit inline NegativeAccuracy();
81  // No explicitly declared copy constructor.
83  //**********************************************************************************************
84 
85  public:
86  //**Destructor**********************************************************************************
87  // No explicitly declared destructor.
88  //**********************************************************************************************
89 
90  //**Unary plus/minus operators******************************************************************
93  inline const NegativeAccuracy& operator+() const;
94  inline const PositiveType operator-() const;
96  //**********************************************************************************************
97 
98  //**Conversion operator*************************************************************************
101  template< typename T >
102  inline operator const T() const;
104  //**********************************************************************************************
105 
106  private:
107  //**Forbidden operations************************************************************************
111  void* operator&() const;
112 
113  //**********************************************************************************************
114 
115  //**Friend declarations*************************************************************************
117  friend class Accuracy;
119  //**********************************************************************************************
120 };
121 //*************************************************************************************************
122 
123 
124 
125 
126 //=================================================================================================
127 //
128 // CONSTRUCTOR
129 //
130 //=================================================================================================
131 
132 //*************************************************************************************************
135 template< typename A > // Positive accuracy type
137 {}
138 //*************************************************************************************************
139 
140 
141 
142 
143 //=================================================================================================
144 //
145 // UNARY PLUS/MINUS OPERATORS
146 //
147 //=================================================================================================
148 
149 //*************************************************************************************************
154 template< typename A > // Positive accuracy type
156 {
157  return *this;
158 }
159 //*************************************************************************************************
160 
161 
162 //*************************************************************************************************
167 template< typename A > // Positive accuracy type
169 {
170  return PositiveType();
171 }
172 //*************************************************************************************************
173 
174 
175 
176 
177 //=================================================================================================
178 //
179 // CONVERSION OPERATOR
180 //
181 //=================================================================================================
182 
183 //*************************************************************************************************
189 template< typename A > // Positive accuracy type
190 template< typename T > // Floating point data type
191 inline NegativeAccuracy<A>::operator const T() const
192 {
194  return -Limits<T>::accuracy();
195 }
196 //*************************************************************************************************
197 
198 
199 
200 
201 //=================================================================================================
202 //
203 // GLOBAL OPERATORS
204 //
205 //=================================================================================================
206 
207 //*************************************************************************************************
210 template< typename A, typename T >
211 inline bool operator==( const NegativeAccuracy<A>& lhs, const T& rhs );
212 
213 template< typename A, typename T >
214 inline bool operator==( const T& lhs, const NegativeAccuracy<A>& rhs );
215 
216 template< typename A, typename T >
217 inline bool operator!=( const NegativeAccuracy<A>& lhs, const T& rhs );
218 
219 template< typename A, typename T >
220 inline bool operator!=( const T& lhs, const NegativeAccuracy<A>& rhs );
221 
222 template< typename A, typename T >
223 inline bool operator<( const NegativeAccuracy<A>& lhs, const T& rhs );
224 
225 template< typename A, typename T >
226 inline bool operator<( const T& lhs, const NegativeAccuracy<A>& rhs );
227 
228 template< typename A, typename T >
229 inline bool operator>( const NegativeAccuracy<A>& lhs, const T& rhs );
230 
231 template< typename A, typename T >
232 inline bool operator>( const T& lhs, const NegativeAccuracy<A>& rhs );
234 //*************************************************************************************************
235 
236 
237 //*************************************************************************************************
247 template< typename A // Positive accuracy type
248  , typename T > // Floating point data type
249 inline bool operator==( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
250 {
252  return -Limits<T>::accuracy() == rhs;
253 }
254 //*************************************************************************************************
255 
256 
257 //*************************************************************************************************
267 template< typename A // Positive accuracy type
268  , typename T > // Floating point data type
269 inline bool operator==( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
270 {
272  return lhs == -Limits<T>::accuracy();
273 }
274 //*************************************************************************************************
275 
276 
277 //*************************************************************************************************
287 template< typename A // Positive accuracy type
288  , typename T > // Floating point data type
289 inline bool operator!=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
290 {
292  return -Limits<T>::accuracy() != rhs;
293 }
294 //*************************************************************************************************
295 
296 
297 //*************************************************************************************************
307 template< typename A // Positive accuracy type
308  , typename T > // Floating point data type
309 inline bool operator!=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
310 {
312  return lhs != -Limits<T>::accuracy();
313 }
314 //*************************************************************************************************
315 
316 
317 //*************************************************************************************************
326 template< typename A // Positive accuracy type
327  , typename T > // Floating point data type
328 inline bool operator<( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
329 {
331  return -Limits<T>::accuracy() < rhs;
332 }
333 //*************************************************************************************************
334 
335 
336 //*************************************************************************************************
345 template< typename A // Positive accuracy type
346  , typename T > // Floating point data type
347 inline bool operator<( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
348 {
350  return lhs < -Limits<T>::accuracy();
351 }
352 //*************************************************************************************************
353 
354 
355 //*************************************************************************************************
364 template< typename A // Positive accuracy type
365  , typename T > // Floating point data type
366 inline bool operator>( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
367 {
369  return -Limits<T>::accuracy() > rhs;
370 }
371 //*************************************************************************************************
372 
373 
374 //*************************************************************************************************
383 template< typename A // Positive accuracy type
384  , typename T > // Floating point data type
385 inline bool operator>( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
386 {
388  return lhs > -Limits<T>::accuracy();
389 }
390 //*************************************************************************************************
391 
392 
393 //*************************************************************************************************
402 template< typename A // Positive accuracy type
403  , typename T > // Floating point data type
404 inline bool operator<=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
405 {
407  return -Limits<T>::accuracy() <= rhs;
408 }
409 //*************************************************************************************************
410 
411 
412 //*************************************************************************************************
421 template< typename A // Positive accuracy type
422  , typename T > // Floating point data type
423 inline bool operator<=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
424 {
426  return lhs <= -Limits<T>::accuracy();
427 }
428 //*************************************************************************************************
429 
430 
431 //*************************************************************************************************
440 template< typename A // Positive accuracy type
441  , typename T > // Floating point data type
442 inline bool operator>=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
443 {
445  return -Limits<T>::accuracy() >= rhs;
446 }
447 //*************************************************************************************************
448 
449 
450 //*************************************************************************************************
459 template< typename A // Positive accuracy type
460  , typename T > // Floating point data type
461 inline bool operator>=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
462 {
464  return lhs >= -Limits<T>::accuracy();
465 }
466 //*************************************************************************************************
467 
468 
469 
470 
471 
472 
473 
474 
475 //=================================================================================================
476 //
477 // CLASS DEFINITION
478 //
479 //=================================================================================================
480 
481 //*************************************************************************************************
497 class Accuracy
498 {
499  public:
500  //**Type definitions****************************************************************************
502  //**********************************************************************************************
503 
504  //**Constructor*********************************************************************************
507  explicit inline Accuracy();
508  // No explicitly declared copy constructor.
510  //**********************************************************************************************
511 
512  //**Destructor**********************************************************************************
513  // No explicitly declared destructor.
514  //**********************************************************************************************
515 
516  //**Unary plus/minus operators******************************************************************
519  inline const Accuracy& operator+() const;
520  inline const NegativeType operator-() const;
522  //**********************************************************************************************
523 
524  //**Conversion operator*************************************************************************
527  template< typename T >
528  inline operator const T() const;
530  //**********************************************************************************************
531 
532  private:
533  //**Forbidden operations************************************************************************
536  Accuracy& operator=( const Accuracy& );
537  void* operator&() const;
538 
539  //**********************************************************************************************
540 };
541 //*************************************************************************************************
542 
543 
544 
545 
546 //=================================================================================================
547 //
548 // CONSTRUCTOR
549 //
550 //=================================================================================================
551 
552 //*************************************************************************************************
556 {}
557 //*************************************************************************************************
558 
559 
560 
561 
562 //=================================================================================================
563 //
564 // UNARY PLUS/MINUS OPERATORS
565 //
566 //=================================================================================================
567 
568 //*************************************************************************************************
573 inline const Accuracy& Accuracy::operator+() const
574 {
575  return *this;
576 }
577 //*************************************************************************************************
578 
579 
580 //*************************************************************************************************
586 {
587  return NegativeType();
588 }
589 //*************************************************************************************************
590 
591 
592 
593 
594 //=================================================================================================
595 //
596 // CONVERSION OPERATOR
597 //
598 //=================================================================================================
599 
600 //*************************************************************************************************
606 template< typename T > // Floating point data type
607 inline Accuracy::operator const T() const
608 {
610  return Limits<T>::accuracy();
611 }
612 //*************************************************************************************************
613 
614 
615 
616 
617 //=================================================================================================
618 //
619 // GLOBAL OPERATORS
620 //
621 //=================================================================================================
622 
623 //*************************************************************************************************
626 template< typename T >
627 inline bool operator==( const Accuracy& lhs, const T& rhs );
628 
629 template< typename T >
630 inline bool operator==( const T& lhs, const Accuracy& rhs );
631 
632 template< typename T >
633 inline bool operator!=( const Accuracy& lhs, const T& rhs );
634 
635 template< typename T >
636 inline bool operator!=( const T& lhs, const Accuracy& rhs );
637 
638 template< typename T >
639 inline bool operator<( const Accuracy& lhs, const T& rhs );
640 
641 template< typename T >
642 inline bool operator<( const T& lhs, const Accuracy& rhs );
643 
644 template< typename T >
645 inline bool operator>( const Accuracy& lhs, const T& rhs );
646 
647 template< typename T >
648 inline bool operator>( const T& lhs, const Accuracy& rhs );
649 
650 template< typename T >
651 inline bool operator<=( const Accuracy& lhs, const T& rhs );
652 
653 template< typename T >
654 inline bool operator<=( const T& lhs, const Accuracy& rhs );
655 
656 template< typename T >
657 inline bool operator>=( const Accuracy& lhs, const T& rhs );
658 
659 template< typename T >
660 inline bool operator>=( const T& lhs, const Accuracy& rhs );
662 //*************************************************************************************************
663 
664 
665 //*************************************************************************************************
675 template< typename T > // Floating point data type
676 inline bool operator==( const Accuracy& /*lhs*/, const T& rhs )
677 {
679  return Limits<T>::accuracy() == rhs;
680 }
681 //*************************************************************************************************
682 
683 
684 //*************************************************************************************************
694 template< typename T > // Floating point data type
695 inline bool operator==( const T& lhs, const Accuracy& /*rhs*/ )
696 {
698  return lhs == Limits<T>::accuracy();
699 }
700 //*************************************************************************************************
701 
702 
703 //*************************************************************************************************
713 template< typename T > // Floating point data type
714 inline bool operator!=( const Accuracy& /*lhs*/, const T& rhs )
715 {
717  return Limits<T>::accuracy() != rhs;
718 }
719 //*************************************************************************************************
720 
721 
722 //*************************************************************************************************
732 template< typename T > // Floating point data type
733 inline bool operator!=( const T& lhs, const Accuracy& /*rhs*/ )
734 {
736  return lhs != Limits<T>::accuracy();
737 }
738 //*************************************************************************************************
739 
740 
741 //*************************************************************************************************
750 template< typename T > // Floating point data type
751 inline bool operator<( const Accuracy& /*lhs*/, const T& rhs )
752 {
754  return Limits<T>::accuracy() < rhs;
755 }
756 //*************************************************************************************************
757 
758 
759 //*************************************************************************************************
768 template< typename T > // Floating point data type
769 inline bool operator<( const T& lhs, const Accuracy& /*rhs*/ )
770 {
772  return lhs < Limits<T>::accuracy();
773 }
774 //*************************************************************************************************
775 
776 
777 //*************************************************************************************************
786 template< typename T > // Floating point data type
787 inline bool operator>( const Accuracy& /*lhs*/, const T& rhs )
788 {
790  return Limits<T>::accuracy() > rhs;
791 }
792 //*************************************************************************************************
793 
794 
795 //*************************************************************************************************
804 template< typename T > // Floating point data type
805 inline bool operator>( const T& lhs, const Accuracy& /*rhs*/ )
806 {
808  return lhs > Limits<T>::accuracy();
809 }
810 //*************************************************************************************************
811 
812 
813 //*************************************************************************************************
822 template< typename T > // Floating point data type
823 inline bool operator<=( const Accuracy& /*lhs*/, const T& rhs )
824 {
826  return Limits<T>::accuracy() <= rhs;
827 }
828 //*************************************************************************************************
829 
830 
831 //*************************************************************************************************
840 template< typename T > // Floating point data type
841 inline bool operator<=( const T& lhs, const Accuracy& /*rhs*/ )
842 {
845 }
846 //*************************************************************************************************
847 
848 
849 //*************************************************************************************************
858 template< typename T > // Floating point data type
859 inline bool operator>=( const Accuracy& /*lhs*/, const T& rhs )
860 {
862  return Limits<T>::accuracy() >= rhs;
863 }
864 //*************************************************************************************************
865 
866 
867 //*************************************************************************************************
876 template< typename T > // Floating point data type
877 inline bool operator>=( const T& lhs, const Accuracy& /*rhs*/ )
878 {
880  return lhs >= Limits<T>::accuracy();
881 }
882 //*************************************************************************************************
883 
884 
885 
886 
887 //=================================================================================================
888 //
889 // GLOBAL ACCURACY VALUE
890 //
891 //=================================================================================================
892 
893 //*************************************************************************************************
902 //*************************************************************************************************
903 
904 } // namespace blaze
905 
906 #endif
Accuracy & operator=(const Accuracy &)
Copy assignment operator (private & undefined)
Numerical limits of built-in data types.
NegativeAccuracy< Accuracy > NegativeType
The negated accuracy type.
Definition: Accuracy.h:501
NegativeAccuracy & operator=(const NegativeAccuracy &)
Copy assignment operator (private & undefined)
bool operator<=(const NegativeAccuracy< A > &, const T &rhs)
Less-or-equal-than comparison between a NegativeAccuracy object and a floating point value...
Definition: Accuracy.h:404
Accuracy()
The default constructor of the Accuracy class.
Definition: Accuracy.h:555
void * operator&() const
Address operator (private & undefined)
bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:366
bool operator>=(const NegativeAccuracy< A > &, const T &rhs)
Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value...
Definition: Accuracy.h:442
NegativeAccuracy()
The default constructor of the NegativeAccuracy class.
Definition: Accuracy.h:136
const NegativeAccuracy & operator+() const
Returns the negative computation accuracy for all floating point data types.
Definition: Accuracy.h:155
Computation accuracy for floating point data types.The Accuracy class is a wrapper class around the f...
Definition: Accuracy.h:497
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
const Accuracy & operator+() const
Returns the positive computation accuracy for all floating point data types.
Definition: Accuracy.h:573
Negative computation accuracy for floating point data types.The NegativeAccuracy class is a wrapper c...
Definition: Accuracy.h:69
const PositiveType operator-() const
Returns the positive computation accuracy for all floating point data types.
Definition: Accuracy.h:168
void * operator&() const
Address operator (private & undefined)
A PositiveType
The positive accuracy type.
Definition: Accuracy.h:73
Constraint on the data type.
const NegativeType operator-() const
Returns the negative computation accuracy for all floating point data types.
Definition: Accuracy.h:585
bool operator<(const NegativeAccuracy< A > &lhs, const T &rhs)
Less-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:328
const Accuracy accuracy
Global Accuracy instance.The blaze::accuracy instance can be used wherever a floating point data type...
Definition: Accuracy.h:901
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
#define BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE(T)
Constraint on the data type.In case the given data type T is not a floating point data type...
Definition: FloatingPoint.h:79