Blaze 3.9
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
47namespace blaze {
48
49//=================================================================================================
50//
51// CLASS DEFINITION
52//
53//=================================================================================================
54
55//*************************************************************************************************
68template< typename E > // Positive epsilon type
70{
71 public:
72 //**Type definitions****************************************************************************
73 using PositiveType = E;
74 //**********************************************************************************************
75
76 private:
77 //**Constructors********************************************************************************
80 constexpr NegativeEpsilon();
81 NegativeEpsilon( const NegativeEpsilon& ) = default;
83 //**********************************************************************************************
84
85 public:
86 //**Destructor**********************************************************************************
89 ~NegativeEpsilon() = default;
91 //**********************************************************************************************
92
93 //**Unary plus/minus operators******************************************************************
96 constexpr const NegativeEpsilon& operator+() const;
97 constexpr const PositiveType operator-() const;
99 //**********************************************************************************************
100
101 //**Conversion operator*************************************************************************
104 template< typename T >
105 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//*************************************************************************************************
138template< typename E > // Positive epsilon type
140{}
141//*************************************************************************************************
142
143
144
145
146//=================================================================================================
147//
148// UNARY PLUS/MINUS OPERATORS
149//
150//=================================================================================================
151
152//*************************************************************************************************
157template< typename E > // Positive epsilon type
159{
160 return *this;
161}
162//*************************************************************************************************
163
164
165//*************************************************************************************************
170template< typename E > // Positive epsilon type
172{
173 return PositiveType();
174}
175//*************************************************************************************************
176
177
178
179
180//=================================================================================================
181//
182// CONVERSION OPERATOR
183//
184//=================================================================================================
185
186//*************************************************************************************************
192template< typename E > // Positive epsilon type
193template< typename T > // Floating point data type
194constexpr 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//*************************************************************************************************
213template< typename E, typename T >
214constexpr bool operator==( const NegativeEpsilon<E>& lhs, const T& rhs );
215
216template< typename E, typename T >
217constexpr bool operator==( const T& lhs, const NegativeEpsilon<E>& rhs );
218
219template< typename E, typename T >
220constexpr bool operator!=( const NegativeEpsilon<E>& lhs, const T& rhs );
221
222template< typename E, typename T >
223constexpr bool operator!=( const T& lhs, const NegativeEpsilon<E>& rhs );
224
225template< typename E, typename T >
226constexpr bool operator<( const NegativeEpsilon<E>& lhs, const T& rhs );
227
228template< typename E, typename T >
229constexpr bool operator<( const T& lhs, const NegativeEpsilon<E>& rhs );
230
231template< typename E, typename T >
232constexpr bool operator>( const NegativeEpsilon<E>& lhs, const T& rhs );
233
234template< typename E, typename T >
235constexpr bool operator>( const T& lhs, const NegativeEpsilon<E>& rhs );
237//*************************************************************************************************
238
239
240//*************************************************************************************************
250template< typename E // Positive epsilon type
251 , typename T > // Floating point data type
252constexpr bool operator==( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
253{
255 return -Limits<T>::epsilon() == rhs;
256}
257//*************************************************************************************************
258
259
260//*************************************************************************************************
270template< typename E // Positive epsilon type
271 , typename T > // Floating point data type
272constexpr bool operator==( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
273{
275 return lhs == -Limits<T>::epsilon();
276}
277//*************************************************************************************************
278
279
280//*************************************************************************************************
290template< typename E // Positive epsilon type
291 , typename T > // Floating point data type
292constexpr bool operator!=( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
293{
295 return -Limits<T>::epsilon() != rhs;
296}
297//*************************************************************************************************
298
299
300//*************************************************************************************************
310template< typename E // Positive epsilon type
311 , typename T > // Floating point data type
312constexpr bool operator!=( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
313{
315 return lhs != -Limits<T>::epsilon();
316}
317//*************************************************************************************************
318
319
320//*************************************************************************************************
329template< typename E // Positive epsilon type
330 , typename T > // Floating point data type
331constexpr bool operator<( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
332{
334 return -Limits<T>::epsilon() < rhs;
335}
336//*************************************************************************************************
337
338
339//*************************************************************************************************
348template< typename E // Positive epsilon type
349 , typename T > // Floating point data type
350constexpr bool operator<( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
351{
353 return lhs < -Limits<T>::epsilon();
354}
355//*************************************************************************************************
356
357
358//*************************************************************************************************
367template< typename E // Positive epsilon type
368 , typename T > // Floating point data type
369constexpr bool operator>( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
370{
372 return -Limits<T>::epsilon() > rhs;
373}
374//*************************************************************************************************
375
376
377//*************************************************************************************************
386template< typename E // Positive epsilon type
387 , typename T > // Floating point data type
388constexpr bool operator>( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
389{
391 return lhs > -Limits<T>::epsilon();
392}
393//*************************************************************************************************
394
395
396//*************************************************************************************************
405template< typename E // Positive epsilon type
406 , typename T > // Floating point data type
407constexpr bool operator<=( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
408{
410 return -Limits<T>::epsilon() <= rhs;
411}
412//*************************************************************************************************
413
414
415//*************************************************************************************************
424template< typename E // Positive epsilon type
425 , typename T > // Floating point data type
426constexpr bool operator<=( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
427{
429 return lhs <= -Limits<T>::epsilon();
430}
431//*************************************************************************************************
432
433
434//*************************************************************************************************
443template< typename E // Positive epsilon type
444 , typename T > // Floating point data type
445constexpr bool operator>=( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
446{
448 return -Limits<T>::epsilon() >= rhs;
449}
450//*************************************************************************************************
451
452
453//*************************************************************************************************
462template< typename E // Positive epsilon type
463 , typename T > // Floating point data type
464constexpr 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//*************************************************************************************************
501{
502 public:
503 //**Type definitions****************************************************************************
505 //**********************************************************************************************
506
507 //**Constructors********************************************************************************
510 constexpr Epsilon();
511 Epsilon( const Epsilon& ) = default;
513 //**********************************************************************************************
514
515 //**Destructor**********************************************************************************
518 ~Epsilon() = default;
520 //**********************************************************************************************
521
522 //**Unary plus/minus operators******************************************************************
525 constexpr const Epsilon& operator+() const;
526 constexpr const NegativeType operator-() const;
528 //**********************************************************************************************
529
530 //**Conversion operators************************************************************************
533 template< typename T >
534 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//*************************************************************************************************
561{}
562//*************************************************************************************************
563
564
565
566
567//=================================================================================================
568//
569// UNARY PLUS/MINUS OPERATORS
570//
571//=================================================================================================
572
573//*************************************************************************************************
578constexpr const Epsilon& Epsilon::operator+() const
579{
580 return *this;
581}
582//*************************************************************************************************
583
584
585//*************************************************************************************************
591{
592 return NegativeType();
593}
594//*************************************************************************************************
595
596
597
598
599//=================================================================================================
600//
601// CONVERSION OPERATORS
602//
603//=================================================================================================
604
605//*************************************************************************************************
611template< typename T >
612constexpr 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//*************************************************************************************************
631template< typename T >
632constexpr bool operator==( const Epsilon& lhs, const T& rhs );
633
634template< typename T >
635constexpr bool operator==( const T& lhs, const Epsilon& rhs );
636
637template< typename T >
638constexpr bool operator!=( const Epsilon& lhs, const T& rhs );
639
640template< typename T >
641constexpr bool operator!=( const T& lhs, const Epsilon& rhs );
642
643template< typename T >
644constexpr bool operator<( const Epsilon& lhs, const T& rhs );
645
646template< typename T >
647constexpr bool operator<( const T& lhs, const Epsilon& rhs );
648
649template< typename T >
650constexpr bool operator>( const Epsilon& lhs, const T& rhs );
651
652template< typename T >
653constexpr bool operator>( const T& lhs, const Epsilon& rhs );
654
655template< typename T >
656constexpr bool operator<=( const Epsilon& lhs, const T& rhs );
657
658template< typename T >
659constexpr bool operator<=( const T& lhs, const Epsilon& rhs );
660
661template< typename T >
662constexpr bool operator>=( const Epsilon& lhs, const T& rhs );
663
664template< typename T >
665constexpr bool operator>=( const T& lhs, const Epsilon& rhs );
667//*************************************************************************************************
668
669
670//*************************************************************************************************
680template< typename T >
681constexpr bool operator==( const Epsilon& /*lhs*/, const T& rhs )
682{
684 return Limits<T>::epsilon() == rhs;
685}
686//*************************************************************************************************
687
688
689//*************************************************************************************************
699template< typename T >
700constexpr bool operator==( const T& lhs, const Epsilon& /*rhs*/ )
701{
703 return lhs == Limits<T>::epsilon();
704}
705//*************************************************************************************************
706
707
708//*************************************************************************************************
718template< typename T >
719constexpr bool operator!=( const Epsilon& /*lhs*/, const T& rhs )
720{
722 return Limits<T>::epsilon() != rhs;
723}
724//*************************************************************************************************
725
726
727//*************************************************************************************************
737template< typename T >
738constexpr bool operator!=( const T& lhs, const Epsilon& /*rhs*/ )
739{
741 return lhs != Limits<T>::epsilon();
742}
743//*************************************************************************************************
744
745
746//*************************************************************************************************
755template< typename T >
756constexpr bool operator<( const Epsilon& /*lhs*/, const T& rhs )
757{
759 return Limits<T>::epsilon() < rhs;
760}
761//*************************************************************************************************
762
763
764//*************************************************************************************************
773template< typename T >
774constexpr bool operator<( const T& lhs, const Epsilon& /*rhs*/ )
775{
778}
779//*************************************************************************************************
780
781
782//*************************************************************************************************
791template< typename T >
792constexpr bool operator>( const Epsilon& /*lhs*/, const T& rhs )
793{
795 return Limits<T>::epsilon() > rhs;
796}
797//*************************************************************************************************
798
799
800//*************************************************************************************************
809template< typename T >
810constexpr bool operator>( const T& lhs, const Epsilon& /*rhs*/ )
811{
813 return lhs > Limits<T>::epsilon();
814}
815//*************************************************************************************************
816
817
818//*************************************************************************************************
827template< typename T >
828constexpr bool operator<=( const Epsilon& /*lhs*/, const T& rhs )
829{
831 return Limits<T>::epsilon() <= rhs;
832}
833//*************************************************************************************************
834
835
836//*************************************************************************************************
845template< typename T >
846constexpr bool operator<=( const T& lhs, const Epsilon& /*rhs*/ )
847{
850}
851//*************************************************************************************************
852
853
854//*************************************************************************************************
863template< typename T >
864constexpr bool operator>=( const Epsilon& /*lhs*/, const T& rhs )
865{
867 return Limits<T>::epsilon() >= rhs;
868}
869//*************************************************************************************************
870
871
872//*************************************************************************************************
881template< typename T >
882constexpr 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//*************************************************************************************************
906constexpr Epsilon epsilon;
907//*************************************************************************************************
908
909} // namespace blaze
910
911#endif
Constraint on the data type.
Numerical limits of built-in data types.
Numerical epsilon value for floating point data types.
Definition: Epsilon.h:501
constexpr const NegativeType operator-() const
Returns the negative epsilon value for all floating point data types.
Definition: Epsilon.h:590
constexpr Epsilon()
The default constructor of the Epsilon class.
Definition: Epsilon.h:560
constexpr const Epsilon & operator+() const
Returns the positive epsilon value for all floating point data types.
Definition: Epsilon.h:578
NegativeEpsilon< Epsilon > NegativeType
The negative epsilon type.
Definition: Epsilon.h:504
Negative epsilon value for floating point data types.
Definition: Epsilon.h:70
constexpr const PositiveType operator-() const
Returns the positive epsilon value for all floating point data types.
Definition: Epsilon.h:171
constexpr NegativeEpsilon()
The default constructor of the NegativeEpsilon class.
Definition: Epsilon.h:139
constexpr const NegativeEpsilon & operator+() const
Returns the negative epsilon value for all floating point data types.
Definition: Epsilon.h:158
E PositiveType
The positive epsilon type.
Definition: Epsilon.h:73
#define BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE(T)
Constraint on the data type.
Definition: FloatingPoint.h:61
constexpr bool operator==(const T &lhs, const Epsilon &rhs)
Equality comparison between a floating point value and an Epsilon object.
Definition: Epsilon.h:700
constexpr bool operator<(const T &lhs, const Epsilon &rhs)
Less-than comparison between a floating point value and an Epsilon object.
Definition: Epsilon.h:774
constexpr bool operator<=(const T &lhs, const Epsilon &rhs)
Less-or-equal-than comparison between a floating point value and an Epsilon object.
Definition: Epsilon.h:846
constexpr bool operator>(const T &lhs, const Epsilon &rhs)
Greater-than comparison between a floating point value and an Epsilon object.
Definition: Epsilon.h:810
constexpr Epsilon epsilon
Global Epsilon instance.
Definition: Epsilon.h:906
constexpr bool operator>=(const T &lhs, const Epsilon &rhs)
Less-or-equal-than comparison between a floating point value and an Epsilon object.
Definition: Epsilon.h:882
constexpr bool operator!=(const T &lhs, const Epsilon &rhs)
Inequality comparison between a floating point value and an Epsilon object.
Definition: Epsilon.h:738