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 
43 #include <blaze/system/Platform.h>
45 #include <blaze/util/Limits.h>
46 #include <blaze/util/Types.h>
47 
48 
49 namespace blaze {
50 
51 //=================================================================================================
52 //
53 // CLASS DEFINITION
54 //
55 //=================================================================================================
56 
57 //*************************************************************************************************
87 template< typename I > // Positive infinity type
89 {
90  public:
91  //**Type definitions****************************************************************************
92  using PositiveType = I;
93  //**********************************************************************************************
94 
95  private:
96  //**Constructors********************************************************************************
99  explicit inline constexpr NegativeInfinity();
100  NegativeInfinity( const NegativeInfinity& ) = default;
102  //**********************************************************************************************
103 
104  public:
105  //**Destructor**********************************************************************************
108  ~NegativeInfinity() = default;
110  //**********************************************************************************************
111 
112  //**Conversion operators************************************************************************
115  inline constexpr operator signed char() const;
116  inline constexpr operator char() const;
117  inline constexpr operator wchar_t() const;
118  inline constexpr operator short() const;
119  inline constexpr operator int() const;
120  inline constexpr operator long() const;
121 #if BLAZE_WIN64_PLATFORM
122  inline constexpr operator ptrdiff_t() const;
123 #endif
124  inline constexpr operator float() const;
125  inline constexpr operator double() const;
126  inline constexpr operator long double() const;
128  //**********************************************************************************************
129 
130  //**Utility functions***************************************************************************
133  template< typename T >
134  inline constexpr bool equal( const T& rhs ) const;
136  //**********************************************************************************************
137 
138  //**Forbidden operations************************************************************************
141  NegativeInfinity& operator=( const NegativeInfinity& ) = delete;
142  void* operator&() const = delete;
144  //**********************************************************************************************
145 
146  private:
147  //**Friend declarations*************************************************************************
149  friend class Infinity;
151  //**********************************************************************************************
152 };
153 //*************************************************************************************************
154 
155 
156 
157 
158 //=================================================================================================
159 //
160 // CONSTRUCTORS
161 //
162 //=================================================================================================
163 
164 //*************************************************************************************************
167 template< typename I > // Positive infinity type
169 {}
170 //*************************************************************************************************
171 
172 
173 
174 
175 //=================================================================================================
176 //
177 // CONVERSION OPERATORS
178 //
179 //=================================================================================================
180 
181 //*************************************************************************************************
186 template< typename I > // Positive infinity type
187 inline constexpr NegativeInfinity<I>::operator signed char() const
188 {
189  return Limits<signed char>::ninf();
190 }
191 //*************************************************************************************************
192 
193 
194 //*************************************************************************************************
199 template< typename I > // Positive infinity type
200 inline constexpr NegativeInfinity<I>::operator char() const
201 {
202  return Limits<char>::ninf();
203 }
204 //*************************************************************************************************
205 
206 
207 //*************************************************************************************************
212 template< typename I > // Positive infinity type
213 inline constexpr NegativeInfinity<I>::operator wchar_t() const
214 {
215  return Limits<wchar_t>::ninf();
216 }
217 //*************************************************************************************************
218 
219 
220 //*************************************************************************************************
225 template< typename I > // Positive infinity type
226 inline constexpr NegativeInfinity<I>::operator short() const
227 {
228  return Limits<short>::ninf();
229 }
230 //*************************************************************************************************
231 
232 
233 //*************************************************************************************************
238 template< typename I > // Positive infinity type
239 inline constexpr NegativeInfinity<I>::operator int() const
240 {
241  return Limits<int>::ninf();
242 }
243 //*************************************************************************************************
244 
245 
246 //*************************************************************************************************
251 template< typename I > // Positive infinity type
252 inline constexpr NegativeInfinity<I>::operator long() const
253 {
254  return Limits<long>::ninf();
255 }
256 //*************************************************************************************************
257 
258 
259 //*************************************************************************************************
260 #if BLAZE_WIN64_PLATFORM
261 
265 template< typename I > // Positive infinity type
266 inline constexpr NegativeInfinity<I>::operator ptrdiff_t() const
267 {
268  return Limits<ptrdiff_t>::ninf();
269 }
270 #endif
271 //*************************************************************************************************
272 
273 
274 //*************************************************************************************************
279 template< typename I > // Positive infinity type
280 inline constexpr NegativeInfinity<I>::operator float() const
281 {
282  return Limits<float>::ninf();
283 }
284 //*************************************************************************************************
285 
286 
287 //*************************************************************************************************
292 template< typename I > // Positive infinity type
293 inline constexpr NegativeInfinity<I>::operator double() const
294 {
295  return Limits<double>::ninf();
296 }
297 //*************************************************************************************************
298 
299 
300 //*************************************************************************************************
305 template< typename I > // Positive infinity type
306 inline constexpr NegativeInfinity<I>::operator long double() const
307 {
308  return Limits<long double>::ninf();
309 }
310 //*************************************************************************************************
311 
312 
313 
314 
315 //=================================================================================================
316 //
317 // UTILITY FUNCTIONS
318 //
319 //=================================================================================================
320 
321 //*************************************************************************************************
328 template< typename I > // Positive infinity type
329 template< typename T > // Built-in data type
330 inline constexpr bool NegativeInfinity<I>::equal( const T& rhs ) const
331 {
333  return Limits<T>::ninf() == rhs;
334 }
335 //*************************************************************************************************
336 
337 
338 
339 
340 //=================================================================================================
341 //
342 // GLOBAL OPERATORS
343 //
344 //=================================================================================================
345 
346 //*************************************************************************************************
349 template< typename I1, typename I2 >
350 constexpr bool operator==( const NegativeInfinity<I1>& lhs, const NegativeInfinity<I2>& rhs );
351 
352 template< typename I, typename T >
353 constexpr bool operator==( const NegativeInfinity<I>& lhs, const T& rhs );
354 
355 template< typename I, typename T >
356 constexpr bool operator==( const T& lhs, const NegativeInfinity<I>& rhs );
357 
358 template< typename I1, typename I2 >
359 constexpr bool operator!=( const NegativeInfinity<I1>& lhs, const NegativeInfinity<I2>& rhs );
360 
361 template< typename I, typename T >
362 constexpr bool operator!=( const NegativeInfinity<I>& lhs, const T& rhs );
363 
364 template< typename I, typename T >
365 constexpr bool operator!=( const T& lhs, const NegativeInfinity<I>& rhs );
367 //*************************************************************************************************
368 
369 
370 //*************************************************************************************************
376 template< typename I1 // Left-hand side positive infinity type
377  , typename I2 > // Right-hand side positive infinity type
378 inline constexpr bool operator==( const NegativeInfinity<I1>& /*lhs*/, const NegativeInfinity<I2>& /*rhs*/ )
379 {
380  return true;
381 }
382 //*************************************************************************************************
383 
384 
385 //*************************************************************************************************
396 template< typename I // Positive infinity type
397  , typename T > // Built-in data type
398 inline constexpr bool operator==( const NegativeInfinity<I>& lhs, const T& rhs )
399 {
400  return lhs.equal( rhs );
401 }
402 //*************************************************************************************************
403 
404 
405 //*************************************************************************************************
416 template< typename I // Positive infinity type
417  , typename T > // Built-in data type
418 inline constexpr bool operator==( const T& lhs, const NegativeInfinity<I>& rhs )
419 {
420  return rhs.equal( lhs );
421 }
422 //*************************************************************************************************
423 
424 
425 //*************************************************************************************************
431 template< typename I1 // Left-hand side positive infinity type
432  , typename I2 > // Right-hand side positive infinity type
433 inline constexpr bool operator!=( const NegativeInfinity<I1>& /*lhs*/, const NegativeInfinity<I2>& /*rhs*/ )
434 {
435  return false;
436 }
437 //*************************************************************************************************
438 
439 
440 //*************************************************************************************************
451 template< typename I // Positive infinity type
452  , typename T > // Built-in data type
453 inline constexpr bool operator!=( const NegativeInfinity<I>& lhs, const T& rhs )
454 {
455  return !lhs.equal( rhs );
456 }
457 //*************************************************************************************************
458 
459 
460 //*************************************************************************************************
471 template< typename I // Positive infinity type
472  , typename T > // Built-in data type
473 inline constexpr bool operator!=( const T& lhs, const NegativeInfinity<I>& rhs )
474 {
475  return !rhs.equal( lhs );
476 }
477 //*************************************************************************************************
478 
479 
480 
481 
482 
483 
484 
485 
486 //=================================================================================================
487 //
488 // CLASS DEFINITION
489 //
490 //=================================================================================================
491 
492 //*************************************************************************************************
528 class Infinity
529 {
530  public:
531  //**Type definitions****************************************************************************
533  //**********************************************************************************************
534 
535  //**Constructors********************************************************************************
538  explicit inline constexpr Infinity();
539  Infinity( const Infinity& ) = default;
541  //**********************************************************************************************
542 
543  //**Destructor**********************************************************************************
546  ~Infinity() = default;
548  //**********************************************************************************************
549 
550  //**Conversion operators************************************************************************
553  inline constexpr operator unsigned char() const;
554  inline constexpr operator signed char() const;
555  inline constexpr operator char() const;
556  inline constexpr operator wchar_t() const;
557  inline constexpr operator unsigned short() const;
558  inline constexpr operator short() const;
559  inline constexpr operator unsigned int() const;
560  inline constexpr operator int() const;
561  inline constexpr operator unsigned long() const;
562  inline constexpr operator long() const;
563 #if BLAZE_WIN64_PLATFORM
564  inline constexpr operator size_t() const;
565  inline constexpr operator ptrdiff_t() const;
566 #endif
567  inline constexpr operator float() const;
568  inline constexpr operator double() const;
569  inline constexpr operator long double() const;
571  //**********************************************************************************************
572 
573  //**Arithmetic operators************************************************************************
576  inline constexpr const Infinity& operator+() const;
577  inline constexpr const NegativeType operator-() const;
579  //**********************************************************************************************
580 
581  //**Utility functions***************************************************************************
584  template< typename T >
585  inline constexpr bool equal( const T& rhs ) const;
587  //**********************************************************************************************
588 
589  //**Forbidden operations************************************************************************
592  Infinity& operator=( const Infinity& ) = delete;
593  void* operator&() const = delete;
595  //**********************************************************************************************
596 };
597 //*************************************************************************************************
598 
599 
600 
601 
602 //=================================================================================================
603 //
604 // CONSTRUCTORS
605 //
606 //=================================================================================================
607 
608 //*************************************************************************************************
611 inline constexpr Infinity::Infinity()
612 {}
613 //*************************************************************************************************
614 
615 
616 
617 
618 //=================================================================================================
619 //
620 // CONVERSION OPERATORS
621 //
622 //=================================================================================================
623 
624 //*************************************************************************************************
629 inline constexpr Infinity::operator unsigned char() const
630 {
632 }
633 //*************************************************************************************************
634 
635 
636 //*************************************************************************************************
641 inline constexpr Infinity::operator char() const
642 {
643  return Limits<char>::inf();
644 }
645 //*************************************************************************************************
646 
647 
648 //*************************************************************************************************
653 inline constexpr Infinity::operator signed char() const
654 {
655  return Limits<signed char>::inf();
656 }
657 //*************************************************************************************************
658 
659 
660 //*************************************************************************************************
665 inline constexpr Infinity::operator wchar_t() const
666 {
667  return Limits<wchar_t>::inf();
668 }
669 //*************************************************************************************************
670 
671 
672 //*************************************************************************************************
677 inline constexpr Infinity::operator unsigned short() const
678 {
680 }
681 //*************************************************************************************************
682 
683 
684 //*************************************************************************************************
689 inline constexpr Infinity::operator short() const
690 {
691  return Limits<short>::inf();
692 }
693 //*************************************************************************************************
694 
695 
696 //*************************************************************************************************
701 inline constexpr Infinity::operator unsigned int() const
702 {
703  return Limits<unsigned int>::inf();
704 }
705 //*************************************************************************************************
706 
707 
708 //*************************************************************************************************
713 inline constexpr Infinity::operator int() const
714 {
715  return Limits<int>::inf();
716 }
717 //*************************************************************************************************
718 
719 
720 //*************************************************************************************************
725 inline constexpr Infinity::operator unsigned long() const
726 {
728 }
729 //*************************************************************************************************
730 
731 
732 //*************************************************************************************************
737 inline constexpr Infinity::operator long() const
738 {
739  return Limits<long>::inf();
740 }
741 //*************************************************************************************************
742 
743 
744 //*************************************************************************************************
745 #if BLAZE_WIN64_PLATFORM
746 
750 inline constexpr Infinity::operator size_t() const
751 {
752  return Limits<size_t>::inf();
753 }
754 #endif
755 //*************************************************************************************************
756 
757 
758 //*************************************************************************************************
759 #if BLAZE_WIN64_PLATFORM
760 
764 inline constexpr Infinity::operator ptrdiff_t() const
765 {
766  return Limits<ptrdiff_t>::inf();
767 }
768 #endif
769 //*************************************************************************************************
770 
771 
772 //*************************************************************************************************
777 inline constexpr Infinity::operator float() const
778 {
779  return Limits<float>::inf();
780 }
781 //*************************************************************************************************
782 
783 
784 //*************************************************************************************************
789 inline constexpr Infinity::operator double() const
790 {
791  return Limits<double>::inf();
792 }
793 //*************************************************************************************************
794 
795 
796 //*************************************************************************************************
801 inline constexpr Infinity::operator long double() const
802 {
803  return Limits<long double>::inf();
804 }
805 //*************************************************************************************************
806 
807 
808 
809 
810 //=================================================================================================
811 //
812 // ARITHMETIC OPERATORS
813 //
814 //=================================================================================================
815 
816 //*************************************************************************************************
821 inline constexpr const Infinity& Infinity::operator+() const
822 {
823  return *this;
824 }
825 //*************************************************************************************************
826 
827 
828 //*************************************************************************************************
833 inline constexpr const Infinity::NegativeType Infinity::operator-() const
834 {
835  return NegativeType();
836 }
837 //*************************************************************************************************
838 
839 
840 
841 
842 //=================================================================================================
843 //
844 // UTILITY FUNCTIONS
845 //
846 //=================================================================================================
847 
848 //*************************************************************************************************
855 template< typename T >
856 inline constexpr bool Infinity::equal( const T& rhs ) const
857 {
859  return Limits<T>::inf() == rhs;
860 }
861 //*************************************************************************************************
862 
863 
864 
865 
866 //=================================================================================================
867 //
868 // GLOBAL OPERATORS
869 //
870 //=================================================================================================
871 
872 //*************************************************************************************************
875 constexpr bool operator==( const Infinity& lhs, const Infinity& rhs );
876 
877 template< typename I >
878 constexpr bool operator==( const Infinity& lhs, const NegativeInfinity<I>& rhs );
879 
880 template< typename I >
881 constexpr bool operator==( const NegativeInfinity<I>& lhs, const Infinity& rhs );
882 
883 template< typename T >
884 constexpr bool operator==( const Infinity& lhs, const T& rhs );
885 
886 template< typename T >
887 constexpr bool operator==( const T& lhs, const Infinity& rhs );
888 
889 constexpr bool operator!=( const Infinity& lhs, const Infinity& rhs );
890 
891 template< typename I >
892 constexpr bool operator!=( const Infinity& lhs, const NegativeInfinity<I>& rhs );
893 
894 template< typename I >
895 constexpr bool operator!=( const NegativeInfinity<I>& lhs, const Infinity& rhs );
896 
897 template< typename T >
898 constexpr bool operator!=( const Infinity& lhs, const T& rhs );
899 
900 template< typename T >
901 constexpr bool operator!=( const T& lhs, const Infinity& rhs );
903 //*************************************************************************************************
904 
905 
906 //*************************************************************************************************
912 inline constexpr bool operator==( const Infinity& /*lhs*/, const Infinity& /*rhs*/ )
913 {
914  return true;
915 }
916 //*************************************************************************************************
917 
918 
919 //*************************************************************************************************
925 template< typename I > // Positive infinity type
926 inline constexpr bool operator==( const Infinity& /*lhs*/, const NegativeInfinity<I>& /*rhs*/ )
927 {
928  return false;
929 }
930 //*************************************************************************************************
931 
932 
933 //*************************************************************************************************
939 template< typename I > // Positive infinity type
940 inline constexpr bool operator==( const NegativeInfinity<I>& /*lhs*/, const Infinity& /*rhs*/ )
941 {
942  return false;
943 }
944 //*************************************************************************************************
945 
946 
947 //*************************************************************************************************
958 template< typename T >
959 inline constexpr bool operator==( const Infinity& lhs, const T& rhs )
960 {
961  return lhs.equal( rhs );
962 }
963 //*************************************************************************************************
964 
965 
966 //*************************************************************************************************
977 template< typename T >
978 inline constexpr bool operator==( const T& lhs, const Infinity& rhs )
979 {
980  return rhs.equal( lhs );
981 }
982 //*************************************************************************************************
983 
984 
985 //*************************************************************************************************
991 inline constexpr bool operator!=( const Infinity& /*lhs*/, const Infinity& /*rhs*/ )
992 {
993  return false;
994 }
995 //*************************************************************************************************
996 
997 
998 //*************************************************************************************************
1004 template< typename I > // Positive infinity type
1005 inline constexpr bool operator!=( const Infinity& /*lhs*/, const NegativeInfinity<I>& /*rhs*/ )
1006 {
1007  return true;
1008 }
1009 //*************************************************************************************************
1010 
1011 
1012 //*************************************************************************************************
1018 template< typename I > // Positive infinity type
1019 inline constexpr bool operator!=( const NegativeInfinity<I>& /*lhs*/, const Infinity& /*rhs*/ )
1020 {
1021  return true;
1022 }
1023 //*************************************************************************************************
1024 
1025 
1026 //*************************************************************************************************
1037 template< typename T >
1038 inline constexpr bool operator!=( const Infinity& lhs, const T& rhs )
1039 {
1040  return !lhs.equal( rhs );
1041 }
1042 //*************************************************************************************************
1043 
1044 
1045 //*************************************************************************************************
1056 template< typename T >
1057 inline constexpr bool operator!=( const T& lhs, const Infinity& rhs )
1058 {
1059  return !rhs.equal( lhs );
1060 }
1061 //*************************************************************************************************
1062 
1063 
1064 
1065 
1066 //=================================================================================================
1067 //
1068 // GLOBAL INFINITY VALUE
1069 //
1070 //=================================================================================================
1071 
1072 //*************************************************************************************************
1080 constexpr Infinity inf;
1081 //*************************************************************************************************
1082 
1083 } // namespace blaze
1084 
1085 #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:528
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:330
Negative infinity for built-in data types.The NegativeInfinity class is a wrapper class around the fu...
Definition: Infinity.h:88
I PositiveType
The positive infinity type.
Definition: Infinity.h:92
NegativeInfinity< Infinity > NegativeType
The negative infinity type.
Definition: Infinity.h:532
constexpr NegativeInfinity()
The default constructor of the NegativeInfinity class.
Definition: Infinity.h:168
constexpr const NegativeType operator-() const
Returns the negative infinity value for all built-in data types.
Definition: Infinity.h:833
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
constexpr bool equal(const T &rhs) const
Equality comparison to a built-in data type.
Definition: Infinity.h:856
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 const Infinity & operator+() const
Returns the positive infinity value for all built-in data types.
Definition: Infinity.h:821
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
Numerical limits of built-in data types.The Limits class provides numerical limits for the following ...
Definition: Limits.h:107
#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:611
constexpr Infinity inf
Global Infinity instance.The blaze::inf instance can be used wherever a built-in data type is expecte...
Definition: Infinity.h:1080
Size type of the Blaze library.
Constraint on the data type.
Platform-specific system settings.