Blaze  3.6
Epsilon.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EPSILON_H_
36 #define _BLAZE_MATH_EPSILON_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 E > // Positive epsilon type
70 {
71  public:
72  //**Type definitions****************************************************************************
73  using PositiveType = E;
74  //**********************************************************************************************
75 
76  private:
77  //**Constructors********************************************************************************
80  explicit inline constexpr NegativeEpsilon();
81  NegativeEpsilon( const NegativeEpsilon& ) = default;
83  //**********************************************************************************************
84 
85  public:
86  //**Destructor**********************************************************************************
89  ~NegativeEpsilon() = default;
91  //**********************************************************************************************
92 
93  //**Unary plus/minus operators******************************************************************
96  inline constexpr const NegativeEpsilon& operator+() const;
97  inline constexpr const PositiveType operator-() const;
99  //**********************************************************************************************
100 
101  //**Conversion operator*************************************************************************
104  template< typename T >
105  inline constexpr operator const T() const;
107  //**********************************************************************************************
108 
109  //**Forbidden operations************************************************************************
112  NegativeEpsilon& operator=( const NegativeEpsilon& ) = delete;
113  void* operator&() const = delete;
115  //**********************************************************************************************
116 
117  private:
118  //**Friend declarations*************************************************************************
120  friend class Epsilon;
122  //**********************************************************************************************
123 };
124 //*************************************************************************************************
125 
126 
127 
128 
129 //=================================================================================================
130 //
131 // CONSTRUCTORS
132 //
133 //=================================================================================================
134 
135 //*************************************************************************************************
138 template< typename E > // Positive epsilon type
140 {}
141 //*************************************************************************************************
142 
143 
144 
145 
146 //=================================================================================================
147 //
148 // UNARY PLUS/MINUS OPERATORS
149 //
150 //=================================================================================================
151 
152 //*************************************************************************************************
157 template< typename E > // Positive epsilon type
158 inline constexpr const NegativeEpsilon<E>& NegativeEpsilon<E>::operator+() const
159 {
160  return *this;
161 }
162 //*************************************************************************************************
163 
164 
165 //*************************************************************************************************
170 template< typename E > // Positive epsilon type
172 {
173  return PositiveType();
174 }
175 //*************************************************************************************************
176 
177 
178 
179 
180 //=================================================================================================
181 //
182 // CONVERSION OPERATOR
183 //
184 //=================================================================================================
185 
186 //*************************************************************************************************
192 template< typename E > // Positive epsilon type
193 template< typename T > // Floating point data type
194 inline constexpr NegativeEpsilon<E>::operator const T() const
195 {
197  return -Limits<T>::epsilon();
198 }
199 //*************************************************************************************************
200 
201 
202 
203 
204 //=================================================================================================
205 //
206 // GLOBAL OPERATORS
207 //
208 //=================================================================================================
209 
210 //*************************************************************************************************
213 template< typename E, typename T >
214 constexpr bool operator==( const NegativeEpsilon<E>& lhs, const T& rhs );
215 
216 template< typename E, typename T >
217 constexpr bool operator==( const T& lhs, const NegativeEpsilon<E>& rhs );
218 
219 template< typename E, typename T >
220 constexpr bool operator!=( const NegativeEpsilon<E>& lhs, const T& rhs );
221 
222 template< typename E, typename T >
223 constexpr bool operator!=( const T& lhs, const NegativeEpsilon<E>& rhs );
224 
225 template< typename E, typename T >
226 constexpr bool operator<( const NegativeEpsilon<E>& lhs, const T& rhs );
227 
228 template< typename E, typename T >
229 constexpr bool operator<( const T& lhs, const NegativeEpsilon<E>& rhs );
230 
231 template< typename E, typename T >
232 constexpr bool operator>( const NegativeEpsilon<E>& lhs, const T& rhs );
233 
234 template< typename E, typename T >
235 constexpr bool operator>( const T& lhs, const NegativeEpsilon<E>& rhs );
237 //*************************************************************************************************
238 
239 
240 //*************************************************************************************************
250 template< typename E // Positive epsilon type
251  , typename T > // Floating point data type
252 inline constexpr bool operator==( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
253 {
255  return -Limits<T>::epsilon() == rhs;
256 }
257 //*************************************************************************************************
258 
259 
260 //*************************************************************************************************
270 template< typename E // Positive epsilon type
271  , typename T > // Floating point data type
272 inline constexpr bool operator==( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
273 {
275  return lhs == -Limits<T>::epsilon();
276 }
277 //*************************************************************************************************
278 
279 
280 //*************************************************************************************************
290 template< typename E // Positive epsilon type
291  , typename T > // Floating point data type
292 inline constexpr bool operator!=( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
293 {
295  return -Limits<T>::epsilon() != rhs;
296 }
297 //*************************************************************************************************
298 
299 
300 //*************************************************************************************************
310 template< typename E // Positive epsilon type
311  , typename T > // Floating point data type
312 inline constexpr bool operator!=( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
313 {
315  return lhs != -Limits<T>::epsilon();
316 }
317 //*************************************************************************************************
318 
319 
320 //*************************************************************************************************
329 template< typename E // Positive epsilon type
330  , typename T > // Floating point data type
331 inline constexpr bool operator<( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
332 {
334  return -Limits<T>::epsilon() < rhs;
335 }
336 //*************************************************************************************************
337 
338 
339 //*************************************************************************************************
348 template< typename E // Positive epsilon type
349  , typename T > // Floating point data type
350 inline constexpr bool operator<( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
351 {
353  return lhs < -Limits<T>::epsilon();
354 }
355 //*************************************************************************************************
356 
357 
358 //*************************************************************************************************
367 template< typename E // Positive epsilon type
368  , typename T > // Floating point data type
369 inline constexpr bool operator>( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
370 {
372  return -Limits<T>::epsilon() > rhs;
373 }
374 //*************************************************************************************************
375 
376 
377 //*************************************************************************************************
386 template< typename E // Positive epsilon type
387  , typename T > // Floating point data type
388 inline constexpr bool operator>( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
389 {
391  return lhs > -Limits<T>::epsilon();
392 }
393 //*************************************************************************************************
394 
395 
396 //*************************************************************************************************
405 template< typename E // Positive epsilon type
406  , typename T > // Floating point data type
407 inline constexpr bool operator<=( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
408 {
410  return -Limits<T>::epsilon() <= rhs;
411 }
412 //*************************************************************************************************
413 
414 
415 //*************************************************************************************************
424 template< typename E // Positive epsilon type
425  , typename T > // Floating point data type
426 inline constexpr bool operator<=( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
427 {
429  return lhs <= -Limits<T>::epsilon();
430 }
431 //*************************************************************************************************
432 
433 
434 //*************************************************************************************************
443 template< typename E // Positive epsilon type
444  , typename T > // Floating point data type
445 inline constexpr bool operator>=( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
446 {
448  return -Limits<T>::epsilon() >= rhs;
449 }
450 //*************************************************************************************************
451 
452 
453 //*************************************************************************************************
462 template< typename E // Positive epsilon type
463  , typename T > // Floating point data type
464 inline constexpr bool operator>=( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
465 {
467  return lhs >= -Limits<T>::epsilon();
468 }
469 //*************************************************************************************************
470 
471 
472 
473 
474 
475 
476 
477 
478 //=================================================================================================
479 //
480 // CLASS DEFINITION
481 //
482 //=================================================================================================
483 
484 //*************************************************************************************************
500 class Epsilon
501 {
502  public:
503  //**Type definitions****************************************************************************
505  //**********************************************************************************************
506 
507  //**Constructors********************************************************************************
510  explicit inline constexpr Epsilon();
511  Epsilon( const Epsilon& ) = default;
513  //**********************************************************************************************
514 
515  //**Destructor**********************************************************************************
518  ~Epsilon() = default;
520  //**********************************************************************************************
521 
522  //**Unary plus/minus operators******************************************************************
525  inline constexpr const Epsilon& operator+() const;
526  inline constexpr const NegativeType operator-() const;
528  //**********************************************************************************************
529 
530  //**Conversion operators************************************************************************
533  template< typename T >
534  inline constexpr operator const T() const;
536  //**********************************************************************************************
537 
538  //**Forbidden operations************************************************************************
541  Epsilon& operator=( const Epsilon& ) = delete;
542  void* operator&() const = delete;
544  //**********************************************************************************************
545 };
546 //*************************************************************************************************
547 
548 
549 
550 
551 //=================================================================================================
552 //
553 // CONSTRUCTORS
554 //
555 //=================================================================================================
556 
557 //*************************************************************************************************
560 inline constexpr Epsilon::Epsilon()
561 {}
562 //*************************************************************************************************
563 
564 
565 
566 
567 //=================================================================================================
568 //
569 // UNARY PLUS/MINUS OPERATORS
570 //
571 //=================================================================================================
572 
573 //*************************************************************************************************
578 inline constexpr const Epsilon& Epsilon::operator+() const
579 {
580  return *this;
581 }
582 //*************************************************************************************************
583 
584 
585 //*************************************************************************************************
590 inline constexpr const Epsilon::NegativeType Epsilon::operator-() const
591 {
592  return NegativeType();
593 }
594 //*************************************************************************************************
595 
596 
597 
598 
599 //=================================================================================================
600 //
601 // CONVERSION OPERATORS
602 //
603 //=================================================================================================
604 
605 //*************************************************************************************************
611 template< typename T >
612 inline constexpr Epsilon::operator const T() const
613 {
615  return Limits<T>::epsilon();
616 }
617 //*************************************************************************************************
618 
619 
620 
621 
622 //=================================================================================================
623 //
624 // GLOBAL OPERATORS
625 //
626 //=================================================================================================
627 
628 //*************************************************************************************************
631 template< typename T >
632 constexpr bool operator==( const Epsilon& lhs, const T& rhs );
633 
634 template< typename T >
635 constexpr bool operator==( const T& lhs, const Epsilon& rhs );
636 
637 template< typename T >
638 constexpr bool operator!=( const Epsilon& lhs, const T& rhs );
639 
640 template< typename T >
641 constexpr bool operator!=( const T& lhs, const Epsilon& rhs );
642 
643 template< typename T >
644 constexpr bool operator<( const Epsilon& lhs, const T& rhs );
645 
646 template< typename T >
647 constexpr bool operator<( const T& lhs, const Epsilon& rhs );
648 
649 template< typename T >
650 constexpr bool operator>( const Epsilon& lhs, const T& rhs );
651 
652 template< typename T >
653 constexpr bool operator>( const T& lhs, const Epsilon& rhs );
654 
655 template< typename T >
656 constexpr bool operator<=( const Epsilon& lhs, const T& rhs );
657 
658 template< typename T >
659 constexpr bool operator<=( const T& lhs, const Epsilon& rhs );
660 
661 template< typename T >
662 constexpr bool operator>=( const Epsilon& lhs, const T& rhs );
663 
664 template< typename T >
665 constexpr bool operator>=( const T& lhs, const Epsilon& rhs );
667 //*************************************************************************************************
668 
669 
670 //*************************************************************************************************
680 template< typename T >
681 inline constexpr bool operator==( const Epsilon& /*lhs*/, const T& rhs )
682 {
684  return Limits<T>::epsilon() == rhs;
685 }
686 //*************************************************************************************************
687 
688 
689 //*************************************************************************************************
699 template< typename T >
700 inline constexpr bool operator==( const T& lhs, const Epsilon& /*rhs*/ )
701 {
703  return lhs == Limits<T>::epsilon();
704 }
705 //*************************************************************************************************
706 
707 
708 //*************************************************************************************************
718 template< typename T >
719 inline constexpr bool operator!=( const Epsilon& /*lhs*/, const T& rhs )
720 {
722  return Limits<T>::epsilon() != rhs;
723 }
724 //*************************************************************************************************
725 
726 
727 //*************************************************************************************************
737 template< typename T >
738 inline constexpr bool operator!=( const T& lhs, const Epsilon& /*rhs*/ )
739 {
741  return lhs != Limits<T>::epsilon();
742 }
743 //*************************************************************************************************
744 
745 
746 //*************************************************************************************************
755 template< typename T >
756 inline constexpr bool operator<( const Epsilon& /*lhs*/, const T& rhs )
757 {
759  return Limits<T>::epsilon() < rhs;
760 }
761 //*************************************************************************************************
762 
763 
764 //*************************************************************************************************
773 template< typename T >
774 inline constexpr bool operator<( const T& lhs, const Epsilon& /*rhs*/ )
775 {
777  return lhs < Limits<T>::epsilon();
778 }
779 //*************************************************************************************************
780 
781 
782 //*************************************************************************************************
791 template< typename T >
792 inline constexpr bool operator>( const Epsilon& /*lhs*/, const T& rhs )
793 {
795  return Limits<T>::epsilon() > rhs;
796 }
797 //*************************************************************************************************
798 
799 
800 //*************************************************************************************************
809 template< typename T >
810 inline constexpr bool operator>( const T& lhs, const Epsilon& /*rhs*/ )
811 {
813  return lhs > Limits<T>::epsilon();
814 }
815 //*************************************************************************************************
816 
817 
818 //*************************************************************************************************
827 template< typename T >
828 inline constexpr bool operator<=( const Epsilon& /*lhs*/, const T& rhs )
829 {
831  return Limits<T>::epsilon() <= rhs;
832 }
833 //*************************************************************************************************
834 
835 
836 //*************************************************************************************************
845 template< typename T >
846 inline constexpr bool operator<=( const T& lhs, const Epsilon& /*rhs*/ )
847 {
849  return lhs <= Limits<T>::epsilon();
850 }
851 //*************************************************************************************************
852 
853 
854 //*************************************************************************************************
863 template< typename T >
864 inline constexpr bool operator>=( const Epsilon& /*lhs*/, const T& rhs )
865 {
867  return Limits<T>::epsilon() >= rhs;
868 }
869 //*************************************************************************************************
870 
871 
872 //*************************************************************************************************
881 template< typename T >
882 inline constexpr bool operator>=( const T& lhs, const Epsilon& /*rhs*/ )
883 {
885  return lhs >= Limits<T>::epsilon();
886 }
887 //*************************************************************************************************
888 
889 
890 
891 
892 //=================================================================================================
893 //
894 // GLOBAL EPSILON VALUE
895 //
896 //=================================================================================================
897 
898 //*************************************************************************************************
906 constexpr Epsilon epsilon;
907 //*************************************************************************************************
908 
909 } // namespace blaze
910 
911 #endif
Numerical limits of built-in data types.
constexpr const NegativeType operator-() const
Returns the negative epsilon value for all floating point data types.
Definition: Epsilon.h:590
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:332
constexpr const NegativeEpsilon & operator+() const
Returns the negative epsilon value for all floating point data types.
Definition: Epsilon.h:158
Numerical epsilon value for floating point data types.The Epsilon class is a wrapper class around the...
Definition: Epsilon.h:500
constexpr const PositiveType operator-() const
Returns the positive epsilon value for all floating point data types.
Definition: Epsilon.h:171
constexpr const Epsilon & operator+() const
Returns the positive epsilon value for all floating point data types.
Definition: Epsilon.h:578
E PositiveType
The positive epsilon type.
Definition: Epsilon.h:73
constexpr Epsilon epsilon
Global Epsilon instance.The blaze::epsilon instance can be used wherever a floating point data type i...
Definition: Epsilon.h:906
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
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:370
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:446
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:253
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
constexpr Epsilon()
The default constructor of the Epsilon class.
Definition: Epsilon.h:560
Constraint on the data type.
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:408
constexpr NegativeEpsilon()
The default constructor of the NegativeEpsilon class.
Definition: Epsilon.h:139
Negative epsilon value for floating point data types.The NegativeEpsilon class is a wrapper class aro...
Definition: Epsilon.h:69
NegativeEpsilon< Epsilon > NegativeType
The negative epsilon type.
Definition: Epsilon.h:504
#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