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  using PositiveType = A;
74  //**********************************************************************************************
75 
76  private:
77  //**Constructor*********************************************************************************
80  explicit inline constexpr 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 constexpr const NegativeAccuracy& operator+() const;
94  inline constexpr const PositiveType operator-() const;
96  //**********************************************************************************************
97 
98  //**Conversion operator*************************************************************************
101  template< typename T >
102  inline constexpr 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
168 inline constexpr const typename NegativeAccuracy<A>::PositiveType
170 {
171  return PositiveType();
172 }
173 //*************************************************************************************************
174 
175 
176 
177 
178 //=================================================================================================
179 //
180 // CONVERSION OPERATOR
181 //
182 //=================================================================================================
183 
184 //*************************************************************************************************
190 template< typename A > // Positive accuracy type
191 template< typename T > // Floating point data type
192 inline constexpr NegativeAccuracy<A>::operator const T() const
193 {
195  return -Limits<T>::accuracy();
196 }
197 //*************************************************************************************************
198 
199 
200 
201 
202 //=================================================================================================
203 //
204 // GLOBAL OPERATORS
205 //
206 //=================================================================================================
207 
208 //*************************************************************************************************
211 template< typename A, typename T >
212 inline constexpr bool operator==( const NegativeAccuracy<A>& lhs, const T& rhs );
213 
214 template< typename A, typename T >
215 inline constexpr bool operator==( const T& lhs, const NegativeAccuracy<A>& rhs );
216 
217 template< typename A, typename T >
218 inline constexpr bool operator!=( const NegativeAccuracy<A>& lhs, const T& rhs );
219 
220 template< typename A, typename T >
221 inline constexpr bool operator!=( const T& lhs, const NegativeAccuracy<A>& rhs );
222 
223 template< typename A, typename T >
224 inline constexpr bool operator<( const NegativeAccuracy<A>& lhs, const T& rhs );
225 
226 template< typename A, typename T >
227 inline constexpr bool operator<( const T& lhs, const NegativeAccuracy<A>& rhs );
228 
229 template< typename A, typename T >
230 inline constexpr bool operator>( const NegativeAccuracy<A>& lhs, const T& rhs );
231 
232 template< typename A, typename T >
233 inline constexpr bool operator>( const T& lhs, const NegativeAccuracy<A>& rhs );
235 //*************************************************************************************************
236 
237 
238 //*************************************************************************************************
248 template< typename A // Positive accuracy type
249  , typename T > // Floating point data type
250 inline constexpr bool operator==( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
251 {
253  return -Limits<T>::accuracy() == rhs;
254 }
255 //*************************************************************************************************
256 
257 
258 //*************************************************************************************************
268 template< typename A // Positive accuracy type
269  , typename T > // Floating point data type
270 inline constexpr bool operator==( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
271 {
273  return lhs == -Limits<T>::accuracy();
274 }
275 //*************************************************************************************************
276 
277 
278 //*************************************************************************************************
288 template< typename A // Positive accuracy type
289  , typename T > // Floating point data type
290 inline constexpr bool operator!=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
291 {
293  return -Limits<T>::accuracy() != rhs;
294 }
295 //*************************************************************************************************
296 
297 
298 //*************************************************************************************************
308 template< typename A // Positive accuracy type
309  , typename T > // Floating point data type
310 inline constexpr bool operator!=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
311 {
313  return lhs != -Limits<T>::accuracy();
314 }
315 //*************************************************************************************************
316 
317 
318 //*************************************************************************************************
327 template< typename A // Positive accuracy type
328  , typename T > // Floating point data type
329 inline constexpr bool operator<( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
330 {
332  return -Limits<T>::accuracy() < rhs;
333 }
334 //*************************************************************************************************
335 
336 
337 //*************************************************************************************************
346 template< typename A // Positive accuracy type
347  , typename T > // Floating point data type
348 inline constexpr bool operator<( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
349 {
351  return lhs < -Limits<T>::accuracy();
352 }
353 //*************************************************************************************************
354 
355 
356 //*************************************************************************************************
365 template< typename A // Positive accuracy type
366  , typename T > // Floating point data type
367 inline constexpr bool operator>( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
368 {
370  return -Limits<T>::accuracy() > rhs;
371 }
372 //*************************************************************************************************
373 
374 
375 //*************************************************************************************************
384 template< typename A // Positive accuracy type
385  , typename T > // Floating point data type
386 inline constexpr bool operator>( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
387 {
389  return lhs > -Limits<T>::accuracy();
390 }
391 //*************************************************************************************************
392 
393 
394 //*************************************************************************************************
403 template< typename A // Positive accuracy type
404  , typename T > // Floating point data type
405 inline constexpr bool operator<=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
406 {
408  return -Limits<T>::accuracy() <= rhs;
409 }
410 //*************************************************************************************************
411 
412 
413 //*************************************************************************************************
422 template< typename A // Positive accuracy type
423  , typename T > // Floating point data type
424 inline constexpr bool operator<=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
425 {
427  return lhs <= -Limits<T>::accuracy();
428 }
429 //*************************************************************************************************
430 
431 
432 //*************************************************************************************************
441 template< typename A // Positive accuracy type
442  , typename T > // Floating point data type
443 inline constexpr bool operator>=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
444 {
446  return -Limits<T>::accuracy() >= rhs;
447 }
448 //*************************************************************************************************
449 
450 
451 //*************************************************************************************************
460 template< typename A // Positive accuracy type
461  , typename T > // Floating point data type
462 inline constexpr bool operator>=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
463 {
465  return lhs >= -Limits<T>::accuracy();
466 }
467 //*************************************************************************************************
468 
469 
470 
471 
472 
473 
474 
475 
476 //=================================================================================================
477 //
478 // CLASS DEFINITION
479 //
480 //=================================================================================================
481 
482 //*************************************************************************************************
498 class Accuracy
499 {
500  public:
501  //**Type definitions****************************************************************************
503  //**********************************************************************************************
504 
505  //**Constructor*********************************************************************************
508  explicit inline constexpr Accuracy();
509  // No explicitly declared copy constructor.
511  //**********************************************************************************************
512 
513  //**Destructor**********************************************************************************
514  // No explicitly declared destructor.
515  //**********************************************************************************************
516 
517  //**Unary plus/minus operators******************************************************************
520  inline constexpr const Accuracy& operator+() const;
521  inline constexpr const NegativeType operator-() const;
523  //**********************************************************************************************
524 
525  //**Conversion operator*************************************************************************
528  template< typename T >
529  inline constexpr operator const T() const;
531  //**********************************************************************************************
532 
533  private:
534  //**Forbidden operations************************************************************************
537  Accuracy& operator=( const Accuracy& );
538  void* operator&() const;
539 
540  //**********************************************************************************************
541 };
542 //*************************************************************************************************
543 
544 
545 
546 
547 //=================================================================================================
548 //
549 // CONSTRUCTOR
550 //
551 //=================================================================================================
552 
553 //*************************************************************************************************
556 inline constexpr Accuracy::Accuracy()
557 {}
558 //*************************************************************************************************
559 
560 
561 
562 
563 //=================================================================================================
564 //
565 // UNARY PLUS/MINUS OPERATORS
566 //
567 //=================================================================================================
568 
569 //*************************************************************************************************
574 inline constexpr const Accuracy& Accuracy::operator+() const
575 {
576  return *this;
577 }
578 //*************************************************************************************************
579 
580 
581 //*************************************************************************************************
586 inline constexpr const Accuracy::NegativeType Accuracy::operator-() const
587 {
588  return NegativeType();
589 }
590 //*************************************************************************************************
591 
592 
593 
594 
595 //=================================================================================================
596 //
597 // CONVERSION OPERATOR
598 //
599 //=================================================================================================
600 
601 //*************************************************************************************************
607 template< typename T > // Floating point data type
608 inline constexpr Accuracy::operator const T() const
609 {
611  return Limits<T>::accuracy();
612 }
613 //*************************************************************************************************
614 
615 
616 
617 
618 //=================================================================================================
619 //
620 // GLOBAL OPERATORS
621 //
622 //=================================================================================================
623 
624 //*************************************************************************************************
627 template< typename T >
628 inline constexpr bool operator==( const Accuracy& lhs, const T& rhs );
629 
630 template< typename T >
631 inline constexpr bool operator==( const T& lhs, const Accuracy& rhs );
632 
633 template< typename T >
634 inline constexpr bool operator!=( const Accuracy& lhs, const T& rhs );
635 
636 template< typename T >
637 inline constexpr bool operator!=( const T& lhs, const Accuracy& rhs );
638 
639 template< typename T >
640 inline constexpr bool operator<( const Accuracy& lhs, const T& rhs );
641 
642 template< typename T >
643 inline constexpr bool operator<( const T& lhs, const Accuracy& rhs );
644 
645 template< typename T >
646 inline constexpr bool operator>( const Accuracy& lhs, const T& rhs );
647 
648 template< typename T >
649 inline constexpr bool operator>( const T& lhs, const Accuracy& rhs );
650 
651 template< typename T >
652 inline constexpr bool operator<=( const Accuracy& lhs, const T& rhs );
653 
654 template< typename T >
655 inline constexpr bool operator<=( const T& lhs, const Accuracy& rhs );
656 
657 template< typename T >
658 inline constexpr bool operator>=( const Accuracy& lhs, const T& rhs );
659 
660 template< typename T >
661 inline constexpr bool operator>=( const T& lhs, const Accuracy& rhs );
663 //*************************************************************************************************
664 
665 
666 //*************************************************************************************************
676 template< typename T > // Floating point data type
677 inline constexpr bool operator==( const Accuracy& /*lhs*/, const T& rhs )
678 {
680  return Limits<T>::accuracy() == rhs;
681 }
682 //*************************************************************************************************
683 
684 
685 //*************************************************************************************************
695 template< typename T > // Floating point data type
696 inline constexpr bool operator==( const T& lhs, const Accuracy& /*rhs*/ )
697 {
699  return lhs == Limits<T>::accuracy();
700 }
701 //*************************************************************************************************
702 
703 
704 //*************************************************************************************************
714 template< typename T > // Floating point data type
715 inline constexpr bool operator!=( const Accuracy& /*lhs*/, const T& rhs )
716 {
718  return Limits<T>::accuracy() != rhs;
719 }
720 //*************************************************************************************************
721 
722 
723 //*************************************************************************************************
733 template< typename T > // Floating point data type
734 inline constexpr bool operator!=( const T& lhs, const Accuracy& /*rhs*/ )
735 {
737  return lhs != Limits<T>::accuracy();
738 }
739 //*************************************************************************************************
740 
741 
742 //*************************************************************************************************
751 template< typename T > // Floating point data type
752 inline constexpr bool operator<( const Accuracy& /*lhs*/, const T& rhs )
753 {
755  return Limits<T>::accuracy() < rhs;
756 }
757 //*************************************************************************************************
758 
759 
760 //*************************************************************************************************
769 template< typename T > // Floating point data type
770 inline constexpr bool operator<( const T& lhs, const Accuracy& /*rhs*/ )
771 {
773  return lhs < Limits<T>::accuracy();
774 }
775 //*************************************************************************************************
776 
777 
778 //*************************************************************************************************
787 template< typename T > // Floating point data type
788 inline constexpr bool operator>( const Accuracy& /*lhs*/, const T& rhs )
789 {
791  return Limits<T>::accuracy() > rhs;
792 }
793 //*************************************************************************************************
794 
795 
796 //*************************************************************************************************
805 template< typename T > // Floating point data type
806 inline constexpr bool operator>( const T& lhs, const Accuracy& /*rhs*/ )
807 {
809  return lhs > Limits<T>::accuracy();
810 }
811 //*************************************************************************************************
812 
813 
814 //*************************************************************************************************
823 template< typename T > // Floating point data type
824 inline constexpr bool operator<=( const Accuracy& /*lhs*/, const T& rhs )
825 {
827  return Limits<T>::accuracy() <= rhs;
828 }
829 //*************************************************************************************************
830 
831 
832 //*************************************************************************************************
841 template< typename T > // Floating point data type
842 inline constexpr bool operator<=( const T& lhs, const Accuracy& /*rhs*/ )
843 {
846 }
847 //*************************************************************************************************
848 
849 
850 //*************************************************************************************************
859 template< typename T > // Floating point data type
860 inline constexpr bool operator>=( const Accuracy& /*lhs*/, const T& rhs )
861 {
863  return Limits<T>::accuracy() >= rhs;
864 }
865 //*************************************************************************************************
866 
867 
868 //*************************************************************************************************
877 template< typename T > // Floating point data type
878 inline constexpr bool operator>=( const T& lhs, const Accuracy& /*rhs*/ )
879 {
881  return lhs >= Limits<T>::accuracy();
882 }
883 //*************************************************************************************************
884 
885 
886 
887 
888 //=================================================================================================
889 //
890 // GLOBAL ACCURACY VALUE
891 //
892 //=================================================================================================
893 
894 //*************************************************************************************************
902 constexpr Accuracy accuracy;
903 //*************************************************************************************************
904 
905 } // namespace blaze
906 
907 #endif
Numerical limits of built-in data types.
constexpr const PositiveType operator-() const
Returns the positive computation accuracy for all floating point data types.
Definition: Accuracy.h:169
constexpr Accuracy()
The default constructor of the Accuracy class.
Definition: Accuracy.h:556
NegativeAccuracy & operator=(const NegativeAccuracy &)
Copy assignment operator (private & undefined)
constexpr bool operator<(const NegativeAccuracy< A > &lhs, const T &rhs)
Less-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:329
void * operator &() const
Address operator (private & undefined)
Computation accuracy for floating point data types.The Accuracy class is a wrapper class around the f...
Definition: Accuracy.h:498
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Negative computation accuracy for floating point data types.The NegativeAccuracy class is a wrapper c...
Definition: Accuracy.h:69
constexpr bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:367
constexpr 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:443
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:250
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:290
constexpr const NegativeType operator-() const
Returns the negative computation accuracy for all floating point data types.
Definition: Accuracy.h:586
Constraint on the data type.
A PositiveType
The positive accuracy type.
Definition: Accuracy.h:73
constexpr 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:405
constexpr const NegativeAccuracy & operator+() const
Returns the negative computation accuracy for all floating point data types.
Definition: Accuracy.h:155
constexpr NegativeAccuracy()
The default constructor of the NegativeAccuracy class.
Definition: Accuracy.h:136
constexpr const Accuracy & operator+() const
Returns the positive computation accuracy for all floating point data types.
Definition: Accuracy.h:574
constexpr Accuracy accuracy
Global Accuracy instance.The blaze::accuracy instance can be used wherever a floating point data type...
Definition: Accuracy.h:902
#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:61