Infinity.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_INFINITY_H_
36 #define _BLAZE_MATH_INFINITY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/util/Limits.h>
45 #include <blaze/util/Types.h>
46 
47 
48 namespace blaze {
49 
50 //=================================================================================================
51 //
52 // CLASS DEFINITION
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
86 template< typename I > // Positive infinity type
88 {
89  public:
90  //**Type definitions****************************************************************************
91  using PositiveType = I;
92  //**********************************************************************************************
93 
94  private:
95  //**Constructor*********************************************************************************
98  explicit inline constexpr NegativeInfinity();
99  // No explicitly declared copy constructor.
101  //**********************************************************************************************
102 
103  public:
104  //**Destructor**********************************************************************************
105  // No explicitly declared destructor.
106  //**********************************************************************************************
107 
108  //**Conversion operators************************************************************************
111  inline constexpr operator signed char() const;
112  inline constexpr operator char() const;
113  inline constexpr operator wchar_t() const;
114  inline constexpr operator short() const;
115  inline constexpr operator int() const;
116  inline constexpr operator long() const;
117 #if defined(_WIN64)
118  inline constexpr operator ptrdiff_t() const;
119 #endif
120  inline constexpr operator float() const;
121  inline constexpr operator double() const;
122  inline constexpr operator long double() const;
124  //**********************************************************************************************
125 
126  //**Utility functions***************************************************************************
129  template< typename T >
130  inline constexpr bool equal( const T& rhs ) const;
132  //**********************************************************************************************
133 
134  private:
135  //**Forbidden operations************************************************************************
139  void* operator&() const;
140 
141  //**********************************************************************************************
142 
143  //**Friend declarations*************************************************************************
145  friend class Infinity;
147  //**********************************************************************************************
148 };
149 //*************************************************************************************************
150 
151 
152 
153 
154 //=================================================================================================
155 //
156 // CONSTRUCTOR
157 //
158 //=================================================================================================
159 
160 //*************************************************************************************************
163 template< typename I > // Positive infinity type
165 {}
166 //*************************************************************************************************
167 
168 
169 
170 
171 //=================================================================================================
172 //
173 // CONVERSION OPERATORS
174 //
175 //=================================================================================================
176 
177 //*************************************************************************************************
182 template< typename I > // Positive infinity type
183 inline constexpr NegativeInfinity<I>::operator signed char() const
184 {
185  return Limits<signed char>::ninf();
186 }
187 //*************************************************************************************************
188 
189 
190 //*************************************************************************************************
195 template< typename I > // Positive infinity type
196 inline constexpr NegativeInfinity<I>::operator char() const
197 {
198  return Limits<char>::ninf();
199 }
200 //*************************************************************************************************
201 
202 
203 //*************************************************************************************************
208 template< typename I > // Positive infinity type
209 inline constexpr NegativeInfinity<I>::operator wchar_t() const
210 {
211  return Limits<wchar_t>::ninf();
212 }
213 //*************************************************************************************************
214 
215 
216 //*************************************************************************************************
221 template< typename I > // Positive infinity type
222 inline constexpr NegativeInfinity<I>::operator short() const
223 {
224  return Limits<short>::ninf();
225 }
226 //*************************************************************************************************
227 
228 
229 //*************************************************************************************************
234 template< typename I > // Positive infinity type
235 inline constexpr NegativeInfinity<I>::operator int() const
236 {
237  return Limits<int>::ninf();
238 }
239 //*************************************************************************************************
240 
241 
242 //*************************************************************************************************
247 template< typename I > // Positive infinity type
248 inline constexpr NegativeInfinity<I>::operator long() const
249 {
250  return Limits<long>::ninf();
251 }
252 //*************************************************************************************************
253 
254 
255 //*************************************************************************************************
256 #if defined(_WIN64)
257 
261 template< typename I > // Positive infinity type
262 inline constexpr NegativeInfinity<I>::operator ptrdiff_t() const
263 {
264  return Limits<ptrdiff_t>::ninf();
265 }
266 #endif
267 //*************************************************************************************************
268 
269 
270 //*************************************************************************************************
275 template< typename I > // Positive infinity type
276 inline constexpr NegativeInfinity<I>::operator float() const
277 {
278  return Limits<float>::ninf();
279 }
280 //*************************************************************************************************
281 
282 
283 //*************************************************************************************************
288 template< typename I > // Positive infinity type
289 inline constexpr NegativeInfinity<I>::operator double() const
290 {
291  return Limits<double>::ninf();
292 }
293 //*************************************************************************************************
294 
295 
296 //*************************************************************************************************
301 template< typename I > // Positive infinity type
302 inline constexpr NegativeInfinity<I>::operator long double() const
303 {
304  return Limits<long double>::ninf();
305 }
306 //*************************************************************************************************
307 
308 
309 
310 
311 //=================================================================================================
312 //
313 // UTILITY FUNCTIONS
314 //
315 //=================================================================================================
316 
317 //*************************************************************************************************
324 template< typename I > // Positive infinity type
325 template< typename T > // Built-in data type
326 inline constexpr bool NegativeInfinity<I>::equal( const T& rhs ) const
327 {
329  return Limits<T>::ninf() == rhs;
330 }
331 //*************************************************************************************************
332 
333 
334 
335 
336 //=================================================================================================
337 //
338 // GLOBAL OPERATORS
339 //
340 //=================================================================================================
341 
342 //*************************************************************************************************
345 template< typename I1, typename I2 >
346 inline constexpr bool operator==( const NegativeInfinity<I1>& lhs, const NegativeInfinity<I2>& rhs );
347 
348 template< typename I, typename T >
349 inline constexpr bool operator==( const NegativeInfinity<I>& lhs, const T& rhs );
350 
351 template< typename I, typename T >
352 inline constexpr bool operator==( const T& lhs, const NegativeInfinity<I>& rhs );
353 
354 template< typename I1, typename I2 >
355 inline constexpr bool operator!=( const NegativeInfinity<I1>& lhs, const NegativeInfinity<I2>& rhs );
356 
357 template< typename I, typename T >
358 inline constexpr bool operator!=( const NegativeInfinity<I>& lhs, const T& rhs );
359 
360 template< typename I, typename T >
361 inline constexpr bool operator!=( const T& lhs, const NegativeInfinity<I>& rhs );
363 //*************************************************************************************************
364 
365 
366 //*************************************************************************************************
372 template< typename I1 // Left-hand side positive infinity type
373  , typename I2 > // Right-hand side positive infinity type
374 inline constexpr bool operator==( const NegativeInfinity<I1>& /*lhs*/, const NegativeInfinity<I2>& /*rhs*/ )
375 {
376  return true;
377 }
378 //*************************************************************************************************
379 
380 
381 //*************************************************************************************************
392 template< typename I // Positive infinity type
393  , typename T > // Built-in data type
394 inline constexpr bool operator==( const NegativeInfinity<I>& lhs, const T& rhs )
395 {
396  return lhs.equal( rhs );
397 }
398 //*************************************************************************************************
399 
400 
401 //*************************************************************************************************
412 template< typename I // Positive infinity type
413  , typename T > // Built-in data type
414 inline constexpr bool operator==( const T& lhs, const NegativeInfinity<I>& rhs )
415 {
416  return rhs.equal( lhs );
417 }
418 //*************************************************************************************************
419 
420 
421 //*************************************************************************************************
427 template< typename I1 // Left-hand side positive infinity type
428  , typename I2 > // Right-hand side positive infinity type
429 inline constexpr bool operator!=( const NegativeInfinity<I1>& /*lhs*/, const NegativeInfinity<I2>& /*rhs*/ )
430 {
431  return false;
432 }
433 //*************************************************************************************************
434 
435 
436 //*************************************************************************************************
447 template< typename I // Positive infinity type
448  , typename T > // Built-in data type
449 inline constexpr bool operator!=( const NegativeInfinity<I>& lhs, const T& rhs )
450 {
451  return !lhs.equal( rhs );
452 }
453 //*************************************************************************************************
454 
455 
456 //*************************************************************************************************
467 template< typename I // Positive infinity type
468  , typename T > // Built-in data type
469 inline constexpr bool operator!=( const T& lhs, const NegativeInfinity<I>& rhs )
470 {
471  return !rhs.equal( lhs );
472 }
473 //*************************************************************************************************
474 
475 
476 
477 
478 
479 
480 
481 
482 //=================================================================================================
483 //
484 // CLASS DEFINITION
485 //
486 //=================================================================================================
487 
488 //*************************************************************************************************
524 class Infinity
525 {
526  public:
527  //**Type definitions****************************************************************************
529  //**********************************************************************************************
530 
531  //**Constructor*********************************************************************************
534  explicit inline constexpr Infinity();
536  //**********************************************************************************************
537 
538  //**Destructor**********************************************************************************
539  // No explicitly declared destructor.
540  //**********************************************************************************************
541 
542  //**Conversion operators************************************************************************
545  inline constexpr operator unsigned char() const;
546  inline constexpr operator signed char() const;
547  inline constexpr operator char() const;
548  inline constexpr operator wchar_t() const;
549  inline constexpr operator unsigned short() const;
550  inline constexpr operator short() const;
551  inline constexpr operator unsigned int() const;
552  inline constexpr operator int() const;
553  inline constexpr operator unsigned long() const;
554  inline constexpr operator long() const;
555 #if defined(_WIN64)
556  inline constexpr operator size_t() const;
557  inline constexpr operator ptrdiff_t() const;
558 #endif
559  inline constexpr operator float() const;
560  inline constexpr operator double() const;
561  inline constexpr operator long double() const;
563  //**********************************************************************************************
564 
565  //**Arithmetic operators************************************************************************
568  inline constexpr const Infinity& operator+() const;
569  inline constexpr const NegativeType operator-() const;
571  //**********************************************************************************************
572 
573  //**Utility functions***************************************************************************
576  template< typename T >
577  inline constexpr bool equal( const T& rhs ) const;
579  //**********************************************************************************************
580 
581  private:
582  //**Forbidden operations************************************************************************
585  Infinity& operator=( const Infinity& inf );
586  void* operator&() const;
587 
588  //**********************************************************************************************
589 };
590 //*************************************************************************************************
591 
592 
593 
594 
595 //=================================================================================================
596 //
597 // CONSTRUCTOR
598 //
599 //=================================================================================================
600 
601 //*************************************************************************************************
604 inline constexpr Infinity::Infinity()
605 {}
606 //*************************************************************************************************
607 
608 
609 
610 
611 //=================================================================================================
612 //
613 // CONVERSION OPERATORS
614 //
615 //=================================================================================================
616 
617 //*************************************************************************************************
622 inline constexpr Infinity::operator unsigned char() const
623 {
625 }
626 //*************************************************************************************************
627 
628 
629 //*************************************************************************************************
634 inline constexpr Infinity::operator char() const
635 {
636  return Limits<char>::inf();
637 }
638 //*************************************************************************************************
639 
640 
641 //*************************************************************************************************
646 inline constexpr Infinity::operator signed char() const
647 {
648  return Limits<signed char>::inf();
649 }
650 //*************************************************************************************************
651 
652 
653 //*************************************************************************************************
658 inline constexpr Infinity::operator wchar_t() const
659 {
660  return Limits<wchar_t>::inf();
661 }
662 //*************************************************************************************************
663 
664 
665 //*************************************************************************************************
670 inline constexpr Infinity::operator unsigned short() const
671 {
673 }
674 //*************************************************************************************************
675 
676 
677 //*************************************************************************************************
682 inline constexpr Infinity::operator short() const
683 {
684  return Limits<short>::inf();
685 }
686 //*************************************************************************************************
687 
688 
689 //*************************************************************************************************
694 inline constexpr Infinity::operator unsigned int() const
695 {
696  return Limits<unsigned int>::inf();
697 }
698 //*************************************************************************************************
699 
700 
701 //*************************************************************************************************
706 inline constexpr Infinity::operator int() const
707 {
708  return Limits<int>::inf();
709 }
710 //*************************************************************************************************
711 
712 
713 //*************************************************************************************************
718 inline constexpr Infinity::operator unsigned long() const
719 {
721 }
722 //*************************************************************************************************
723 
724 
725 //*************************************************************************************************
730 inline constexpr Infinity::operator long() const
731 {
732  return Limits<long>::inf();
733 }
734 //*************************************************************************************************
735 
736 
737 //*************************************************************************************************
738 #if defined(_WIN64)
739 
743 inline constexpr Infinity::operator size_t() const
744 {
745  return Limits<size_t>::inf();
746 }
747 #endif
748 //*************************************************************************************************
749 
750 
751 //*************************************************************************************************
752 #if defined(_WIN64)
753 
757 inline constexpr Infinity::operator ptrdiff_t() const
758 {
759  return Limits<ptrdiff_t>::inf();
760 }
761 #endif
762 //*************************************************************************************************
763 
764 
765 //*************************************************************************************************
770 inline constexpr Infinity::operator float() const
771 {
772  return Limits<float>::inf();
773 }
774 //*************************************************************************************************
775 
776 
777 //*************************************************************************************************
782 inline constexpr Infinity::operator double() const
783 {
784  return Limits<double>::inf();
785 }
786 //*************************************************************************************************
787 
788 
789 //*************************************************************************************************
794 inline constexpr Infinity::operator long double() const
795 {
796  return Limits<long double>::inf();
797 }
798 //*************************************************************************************************
799 
800 
801 
802 
803 //=================================================================================================
804 //
805 // ARITHMETIC OPERATORS
806 //
807 //=================================================================================================
808 
809 //*************************************************************************************************
814 inline constexpr const Infinity& Infinity::operator+() const
815 {
816  return *this;
817 }
818 //*************************************************************************************************
819 
820 
821 //*************************************************************************************************
826 inline constexpr const Infinity::NegativeType Infinity::operator-() const
827 {
828  return NegativeType();
829 }
830 //*************************************************************************************************
831 
832 
833 
834 
835 //=================================================================================================
836 //
837 // UTILITY FUNCTIONS
838 //
839 //=================================================================================================
840 
841 //*************************************************************************************************
848 template< typename T >
849 inline constexpr bool Infinity::equal( const T& rhs ) const
850 {
852  return Limits<T>::inf() == rhs;
853 }
854 //*************************************************************************************************
855 
856 
857 
858 
859 //=================================================================================================
860 //
861 // GLOBAL OPERATORS
862 //
863 //=================================================================================================
864 
865 //*************************************************************************************************
868 inline constexpr bool operator==( const Infinity& lhs, const Infinity& rhs );
869 
870 template< typename I >
871 inline constexpr bool operator==( const Infinity& lhs, const NegativeInfinity<I>& rhs );
872 
873 template< typename I >
874 inline constexpr bool operator==( const NegativeInfinity<I>& lhs, const Infinity& rhs );
875 
876 template< typename T >
877 inline constexpr bool operator==( const Infinity& lhs, const T& rhs );
878 
879 template< typename T >
880 inline constexpr bool operator==( const T& lhs, const Infinity& rhs );
881 
882 inline constexpr bool operator!=( const Infinity& lhs, const Infinity& rhs );
883 
884 template< typename I >
885 inline constexpr bool operator!=( const Infinity& lhs, const NegativeInfinity<I>& rhs );
886 
887 template< typename I >
888 inline constexpr bool operator!=( const NegativeInfinity<I>& lhs, const Infinity& rhs );
889 
890 template< typename T >
891 inline constexpr bool operator!=( const Infinity& lhs, const T& rhs );
892 
893 template< typename T >
894 inline constexpr bool operator!=( const T& lhs, const Infinity& rhs );
896 //*************************************************************************************************
897 
898 
899 //*************************************************************************************************
905 inline constexpr bool operator==( const Infinity& /*lhs*/, const Infinity& /*rhs*/ )
906 {
907  return true;
908 }
909 //*************************************************************************************************
910 
911 
912 //*************************************************************************************************
918 template< typename I > // Positive infinity type
919 inline constexpr bool operator==( const Infinity& /*lhs*/, const NegativeInfinity<I>& /*rhs*/ )
920 {
921  return false;
922 }
923 //*************************************************************************************************
924 
925 
926 //*************************************************************************************************
932 template< typename I > // Positive infinity type
933 inline constexpr bool operator==( const NegativeInfinity<I>& /*lhs*/, const Infinity& /*rhs*/ )
934 {
935  return false;
936 }
937 //*************************************************************************************************
938 
939 
940 //*************************************************************************************************
951 template< typename T >
952 inline constexpr bool operator==( const Infinity& lhs, const T& rhs )
953 {
954  return lhs.equal( rhs );
955 }
956 //*************************************************************************************************
957 
958 
959 //*************************************************************************************************
970 template< typename T >
971 inline constexpr bool operator==( const T& lhs, const Infinity& rhs )
972 {
973  return rhs.equal( lhs );
974 }
975 //*************************************************************************************************
976 
977 
978 //*************************************************************************************************
984 inline constexpr bool operator!=( const Infinity& /*lhs*/, const Infinity& /*rhs*/ )
985 {
986  return false;
987 }
988 //*************************************************************************************************
989 
990 
991 //*************************************************************************************************
997 template< typename I > // Positive infinity type
998 inline constexpr bool operator!=( const Infinity& /*lhs*/, const NegativeInfinity<I>& /*rhs*/ )
999 {
1000  return true;
1001 }
1002 //*************************************************************************************************
1003 
1004 
1005 //*************************************************************************************************
1011 template< typename I > // Positive infinity type
1012 inline constexpr bool operator!=( const NegativeInfinity<I>& /*lhs*/, const Infinity& /*rhs*/ )
1013 {
1014  return true;
1015 }
1016 //*************************************************************************************************
1017 
1018 
1019 //*************************************************************************************************
1030 template< typename T >
1031 inline constexpr bool operator!=( const Infinity& lhs, const T& rhs )
1032 {
1033  return !lhs.equal( rhs );
1034 }
1035 //*************************************************************************************************
1036 
1037 
1038 //*************************************************************************************************
1049 template< typename T >
1050 inline constexpr bool operator!=( const T& lhs, const Infinity& rhs )
1051 {
1052  return !rhs.equal( lhs );
1053 }
1054 //*************************************************************************************************
1055 
1056 
1057 
1058 
1059 //=================================================================================================
1060 //
1061 // GLOBAL INFINITY VALUE
1062 //
1063 //=================================================================================================
1064 
1065 //*************************************************************************************************
1073 constexpr Infinity inf;
1074 //*************************************************************************************************
1075 
1076 } // namespace blaze
1077 
1078 #endif
Pointer difference type of the Blaze library.
Positive infinity for built-in data types.The Infinity class is a wrapper class around the functional...
Definition: Infinity.h:524
Numerical limits of built-in data types.
Header file for basic type definitions.
constexpr bool equal(const T &rhs) const
Equality comparison to a built-in data type.
Definition: Infinity.h:326
Negative infinity for built-in data types.The NegativeInfinity class is a wrapper class around the fu...
Definition: Infinity.h:87
const DenseIterator< Type, AF > operator+(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Addition between a DenseIterator and an integral value.
Definition: DenseIterator.h:699
const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:731
I PositiveType
The positive infinity type.
Definition: Infinity.h:91
NegativeInfinity & operator=(const NegativeInfinity &ninf)
Copy assignment operator (private & undefined)
constexpr NegativeInfinity()
The default constructor of the NegativeInfinity class.
Definition: Infinity.h:164
constexpr const NegativeType operator-() const
Returns the negative infinity value for all built-in data types.
Definition: Infinity.h:826
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
void * operator &() const
Address operator (private & undefined)
constexpr bool equal(const T &rhs) const
Equality comparison to a built-in data type.
Definition: Infinity.h:849
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 const Infinity & operator+() const
Returns the positive infinity value for all built-in data types.
Definition: Infinity.h:814
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
Numerical limits of built-in data types.The Limits class provides numerical limits for the following ...
Definition: Limits.h:106
#define BLAZE_CONSTRAINT_MUST_BE_BUILTIN_TYPE(T)
Constraint on the data type.In case the given data type T is not a built-in data type, a compilation error is created.
Definition: Builtin.h:60
constexpr Infinity()
The default constructor of the Infinity class.
Definition: Infinity.h:604
constexpr Infinity inf
Global Infinity instance.The blaze::inf instance can be used wherever a built-in data type is expecte...
Definition: Infinity.h:1073
Size type of the Blaze library.
Constraint on the data type.