All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #include <blaze/util/Unused.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  typedef I PositiveType;
93  //**********************************************************************************************
94 
95  private:
96  //**Constructor*********************************************************************************
99  explicit inline NegativeInfinity();
100  // No explicitly declared copy constructor.
102  //**********************************************************************************************
103 
104  public:
105  //**Destructor**********************************************************************************
106  // No explicitly declared destructor.
107  //**********************************************************************************************
108 
109  //**Conversion operators************************************************************************
112  inline operator signed char() const;
113  inline operator char() const;
114  inline operator wchar_t() const;
115  inline operator short() const;
116  inline operator int() const;
117  inline operator long() const;
118 #if defined(_WIN64)
119  inline operator ptrdiff_t() const;
120 #endif
121  inline operator float() const;
122  inline operator double() const;
123  inline operator long double() const;
125  //**********************************************************************************************
126 
127  //**Utility functions***************************************************************************
130  template< typename T >
131  inline bool equal( const T& rhs ) const;
133  //**********************************************************************************************
134 
135  private:
136  //**Forbidden operations************************************************************************
140  void* operator&() const;
141 
142  //**********************************************************************************************
143 
144  //**Friend declarations*************************************************************************
146  friend class Infinity;
148  //**********************************************************************************************
149 };
150 //*************************************************************************************************
151 
152 
153 
154 
155 //=================================================================================================
156 //
157 // CONSTRUCTOR
158 //
159 //=================================================================================================
160 
161 //*************************************************************************************************
164 template< typename I > // Positive infinity type
166 {}
167 //*************************************************************************************************
168 
169 
170 
171 
172 //=================================================================================================
173 //
174 // CONVERSION OPERATORS
175 //
176 //=================================================================================================
177 
178 //*************************************************************************************************
183 template< typename I > // Positive infinity type
184 inline NegativeInfinity<I>::operator signed char() const
185 {
186  return Limits<signed char>::ninf();
187 }
188 //*************************************************************************************************
189 
190 
191 //*************************************************************************************************
196 template< typename I > // Positive infinity type
197 inline NegativeInfinity<I>::operator char() const
198 {
199  return Limits<char>::ninf();
200 }
201 //*************************************************************************************************
202 
203 
204 //*************************************************************************************************
209 template< typename I > // Positive infinity type
210 inline NegativeInfinity<I>::operator wchar_t() const
211 {
212  return Limits<wchar_t>::ninf();
213 }
214 //*************************************************************************************************
215 
216 
217 //*************************************************************************************************
222 template< typename I > // Positive infinity type
223 inline NegativeInfinity<I>::operator short() const
224 {
225  return Limits<short>::ninf();
226 }
227 //*************************************************************************************************
228 
229 
230 //*************************************************************************************************
235 template< typename I > // Positive infinity type
237 {
238  return Limits<int>::ninf();
239 }
240 //*************************************************************************************************
241 
242 
243 //*************************************************************************************************
248 template< typename I > // Positive infinity type
249 inline NegativeInfinity<I>::operator long() const
250 {
251  return Limits<long>::ninf();
252 }
253 //*************************************************************************************************
254 
255 
256 //*************************************************************************************************
257 #if defined(_WIN64)
258 
262 template< typename I > // Positive infinity type
264 {
265  return Limits<ptrdiff_t>::ninf();
266 }
267 #endif
268 //*************************************************************************************************
269 
270 
271 //*************************************************************************************************
276 template< typename I > // Positive infinity type
277 inline NegativeInfinity<I>::operator float() const
278 {
279  return Limits<float>::ninf();
280 }
281 //*************************************************************************************************
282 
283 
284 //*************************************************************************************************
289 template< typename I > // Positive infinity type
290 inline NegativeInfinity<I>::operator double() const
291 {
292  return Limits<double>::ninf();
293 }
294 //*************************************************************************************************
295 
296 
297 //*************************************************************************************************
302 template< typename I > // Positive infinity type
303 inline NegativeInfinity<I>::operator long double() const
304 {
305  return Limits<long double>::ninf();
306 }
307 //*************************************************************************************************
308 
309 
310 
311 
312 //=================================================================================================
313 //
314 // UTILITY FUNCTIONS
315 //
316 //=================================================================================================
317 
318 //*************************************************************************************************
325 template< typename I > // Positive infinity type
326 template< typename T > // Built-in data type
327 inline bool NegativeInfinity<I>::equal( const T& rhs ) const
328 {
330  return Limits<T>::ninf() == rhs;
331 }
332 //*************************************************************************************************
333 
334 
335 
336 
337 //=================================================================================================
338 //
339 // GLOBAL OPERATORS
340 //
341 //=================================================================================================
342 
343 //*************************************************************************************************
346 template< typename I1, typename I2 >
347 inline bool operator==( const NegativeInfinity<I1>& lhs, const NegativeInfinity<I2>& rhs );
348 
349 template< typename I, typename T >
350 inline bool operator==( const NegativeInfinity<I>& lhs, const T& rhs );
351 
352 template< typename I, typename T >
353 inline bool operator==( const T& lhs, const NegativeInfinity<I>& rhs );
354 
355 template< typename I1, typename I2 >
356 inline bool operator!=( const NegativeInfinity<I1>& lhs, const NegativeInfinity<I2>& rhs );
357 
358 template< typename I, typename T >
359 inline bool operator!=( const NegativeInfinity<I>& lhs, const T& rhs );
360 
361 template< typename I, typename T >
362 inline bool operator!=( const T& lhs, const NegativeInfinity<I>& rhs );
364 //*************************************************************************************************
365 
366 
367 //*************************************************************************************************
375 template< typename I1 // Left-hand side positive infinity type
376  , typename I2 > // Right-hand side positive infinity type
377 inline bool operator==( const NegativeInfinity<I1>& lhs, const NegativeInfinity<I2>& rhs )
378 {
379  UNUSED_PARAMETER( lhs, rhs );
380  return true;
381 }
382 //*************************************************************************************************
383 
384 
385 //*************************************************************************************************
396 template< typename I // Positive infinity type
397  , typename T > // Built-in data type
398 inline 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 bool operator==( const T& lhs, const NegativeInfinity<I>& rhs )
419 {
420  return rhs.equal( lhs );
421 }
422 //*************************************************************************************************
423 
424 
425 //*************************************************************************************************
433 template< typename I1 // Left-hand side positive infinity type
434  , typename I2 > // Right-hand side positive infinity type
435 inline bool operator!=( const NegativeInfinity<I1>& lhs, const NegativeInfinity<I2>& rhs )
436 {
437  UNUSED_PARAMETER( lhs, rhs );
438  return false;
439 }
440 //*************************************************************************************************
441 
442 
443 //*************************************************************************************************
454 template< typename I // Positive infinity type
455  , typename T > // Built-in data type
456 inline bool operator!=( const NegativeInfinity<I>& lhs, const T& rhs )
457 {
458  return !lhs.equal( rhs );
459 }
460 //*************************************************************************************************
461 
462 
463 //*************************************************************************************************
474 template< typename I // Positive infinity type
475  , typename T > // Built-in data type
476 inline bool operator!=( const T& lhs, const NegativeInfinity<I>& rhs )
477 {
478  return !rhs.equal( lhs );
479 }
480 //*************************************************************************************************
481 
482 
483 
484 
485 
486 
487 
488 
489 //=================================================================================================
490 //
491 // CLASS DEFINITION
492 //
493 //=================================================================================================
494 
495 //*************************************************************************************************
531 class Infinity
532 {
533  public:
534  //**Type definitions****************************************************************************
536  //**********************************************************************************************
537 
538  //**Constructor*********************************************************************************
541  explicit inline Infinity();
543  //**********************************************************************************************
544 
545  //**Destructor**********************************************************************************
546  // No explicitly declared destructor.
547  //**********************************************************************************************
548 
549  //**Conversion operators************************************************************************
552  inline operator unsigned char() const;
553  inline operator signed char() const;
554  inline operator char() const;
555  inline operator wchar_t() const;
556  inline operator unsigned short() const;
557  inline operator short() const;
558  inline operator unsigned int() const;
559  inline operator int() const;
560  inline operator unsigned long() const;
561  inline operator long() const;
562 #if defined(_WIN64)
563  inline operator size_t() const;
564  inline operator ptrdiff_t() const;
565 #endif
566  inline operator float() const;
567  inline operator double() const;
568  inline operator long double() const;
570  //**********************************************************************************************
571 
572  //**Arithmetic operators************************************************************************
575  inline const Infinity& operator+() const;
576  inline const NegativeType operator-() const;
578  //**********************************************************************************************
579 
580  //**Utility functions***************************************************************************
583  template< typename T >
584  inline bool equal( const T& rhs ) const;
586  //**********************************************************************************************
587 
588  private:
589  //**Forbidden operations************************************************************************
592  Infinity& operator=( const Infinity& inf );
593  void* operator&() const;
594 
595  //**********************************************************************************************
596 };
597 //*************************************************************************************************
598 
599 
600 
601 
602 //=================================================================================================
603 //
604 // CONSTRUCTOR
605 //
606 //=================================================================================================
607 
608 //*************************************************************************************************
612 {}
613 //*************************************************************************************************
614 
615 
616 
617 
618 //=================================================================================================
619 //
620 // CONVERSION OPERATORS
621 //
622 //=================================================================================================
623 
624 //*************************************************************************************************
629 inline Infinity::operator unsigned char() const
630 {
632 }
633 //*************************************************************************************************
634 
635 
636 //*************************************************************************************************
641 inline Infinity::operator char() const
642 {
643  return Limits<char>::inf();
644 }
645 //*************************************************************************************************
646 
647 
648 //*************************************************************************************************
653 inline Infinity::operator signed char() const
654 {
655  return Limits<signed char>::inf();
656 }
657 //*************************************************************************************************
658 
659 
660 //*************************************************************************************************
665 inline Infinity::operator wchar_t() const
666 {
667  return Limits<wchar_t>::inf();
668 }
669 //*************************************************************************************************
670 
671 
672 //*************************************************************************************************
677 inline Infinity::operator unsigned short() const
678 {
680 }
681 //*************************************************************************************************
682 
683 
684 //*************************************************************************************************
689 inline Infinity::operator short() const
690 {
691  return Limits<short>::inf();
692 }
693 //*************************************************************************************************
694 
695 
696 //*************************************************************************************************
701 inline Infinity::operator unsigned int() const
702 {
703  return Limits<unsigned int>::inf();
704 }
705 //*************************************************************************************************
706 
707 
708 //*************************************************************************************************
713 inline Infinity::operator int() const
714 {
715  return Limits<int>::inf();
716 }
717 //*************************************************************************************************
718 
719 
720 //*************************************************************************************************
725 inline Infinity::operator unsigned long() const
726 {
728 }
729 //*************************************************************************************************
730 
731 
732 //*************************************************************************************************
737 inline Infinity::operator long() const
738 {
739  return Limits<long>::inf();
740 }
741 //*************************************************************************************************
742 
743 
744 //*************************************************************************************************
745 #if defined(_WIN64)
746 
750 inline Infinity::operator size_t() const
751 {
752  return Limits<size_t>::inf();
753 }
754 #endif
755 //*************************************************************************************************
756 
757 
758 //*************************************************************************************************
759 #if defined(_WIN64)
760 
764 inline Infinity::operator ptrdiff_t() const
765 {
766  return Limits<ptrdiff_t>::inf();
767 }
768 #endif
769 //*************************************************************************************************
770 
771 
772 //*************************************************************************************************
777 inline Infinity::operator float() const
778 {
779  return Limits<float>::inf();
780 }
781 //*************************************************************************************************
782 
783 
784 //*************************************************************************************************
789 inline Infinity::operator double() const
790 {
791  return Limits<double>::inf();
792 }
793 //*************************************************************************************************
794 
795 
796 //*************************************************************************************************
801 inline 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 const Infinity& Infinity::operator+() const
822 {
823  return *this;
824 }
825 //*************************************************************************************************
826 
827 
828 //*************************************************************************************************
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 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 inline bool operator==( const Infinity& lhs, const Infinity& rhs );
876 
877 template< typename I >
878 inline bool operator==( const Infinity& lhs, const NegativeInfinity<I>& rhs );
879 
880 template< typename I >
881 inline bool operator==( const NegativeInfinity<I>& lhs, const Infinity& rhs );
882 
883 template< typename T >
884 inline bool operator==( const Infinity& lhs, const T& rhs );
885 
886 template< typename T >
887 inline bool operator==( const T& lhs, const Infinity& rhs );
888 
889 inline bool operator!=( const Infinity& lhs, const Infinity& rhs );
890 
891 template< typename I >
892 inline bool operator!=( const Infinity& lhs, const NegativeInfinity<I>& rhs );
893 
894 template< typename I >
895 inline bool operator!=( const NegativeInfinity<I>& lhs, const Infinity& rhs );
896 
897 template< typename T >
898 inline bool operator!=( const Infinity& lhs, const T& rhs );
899 
900 template< typename T >
901 inline bool operator!=( const T& lhs, const Infinity& rhs );
903 //*************************************************************************************************
904 
905 
906 //*************************************************************************************************
914 inline bool operator==( const Infinity& lhs, const Infinity& rhs )
915 {
916  UNUSED_PARAMETER( lhs, rhs );
917  return true;
918 }
919 //*************************************************************************************************
920 
921 
922 //*************************************************************************************************
930 template< typename I > // Positive infinity type
931 inline bool operator==( const Infinity& lhs, const NegativeInfinity<I>& rhs )
932 {
933  UNUSED_PARAMETER( lhs, rhs );
934  return false;
935 }
936 //*************************************************************************************************
937 
938 
939 //*************************************************************************************************
947 template< typename I > // Positive infinity type
948 inline bool operator==( const NegativeInfinity<I>& lhs, const Infinity& rhs )
949 {
950  UNUSED_PARAMETER( lhs, rhs );
951  return false;
952 }
953 //*************************************************************************************************
954 
955 
956 //*************************************************************************************************
967 template< typename T >
968 inline bool operator==( const Infinity& lhs, const T& rhs )
969 {
970  return lhs.equal( rhs );
971 }
972 //*************************************************************************************************
973 
974 
975 //*************************************************************************************************
986 template< typename T >
987 inline bool operator==( const T& lhs, const Infinity& rhs )
988 {
989  return rhs.equal( lhs );
990 }
991 //*************************************************************************************************
992 
993 
994 //*************************************************************************************************
1002 inline bool operator!=( const Infinity& lhs, const Infinity& rhs )
1003 {
1004  UNUSED_PARAMETER( lhs, rhs );
1005  return false;
1006 }
1007 //*************************************************************************************************
1008 
1009 
1010 //*************************************************************************************************
1018 template< typename I > // Positive infinity type
1019 inline bool operator!=( const Infinity& lhs, const NegativeInfinity<I>& rhs )
1020 {
1021  UNUSED_PARAMETER( lhs, rhs );
1022  return true;
1023 }
1024 //*************************************************************************************************
1025 
1026 
1027 //*************************************************************************************************
1035 template< typename I > // Positive infinity type
1036 inline bool operator!=( const NegativeInfinity<I>& lhs, const Infinity& rhs )
1037 {
1038  UNUSED_PARAMETER( lhs, rhs );
1039  return true;
1040 }
1041 //*************************************************************************************************
1042 
1043 
1044 //*************************************************************************************************
1055 template< typename T >
1056 inline bool operator!=( const Infinity& lhs, const T& rhs )
1057 {
1058  return !lhs.equal( rhs );
1059 }
1060 //*************************************************************************************************
1061 
1062 
1063 //*************************************************************************************************
1074 template< typename T >
1075 inline bool operator!=( const T& lhs, const Infinity& rhs )
1076 {
1077  return !rhs.equal( lhs );
1078 }
1079 //*************************************************************************************************
1080 
1081 
1082 
1083 
1084 //=================================================================================================
1085 //
1086 // GLOBAL INFINITY VALUE
1087 //
1088 //=================================================================================================
1089 
1090 //*************************************************************************************************
1099 //*************************************************************************************************
1100 
1101 } // namespace blaze
1102 
1103 #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:531
Numerical limits of built-in data types.
Header file for the UNUSED_PARAMETER function template.
bool equal(const T &rhs) const
Equality comparison to a built-in data type.
Definition: Infinity.h:327
Infinity & operator=(const Infinity &inf)
Copy assignment operator (private & undefined)
Negative infinity for built-in data types.The NegativeInfinity class is a wrapper class around the fu...
Definition: Infinity.h:88
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:84
void * operator&() const
Address operator (private & undefined)
Infinity()
The default constructor of the Infinity class.
Definition: Infinity.h:611
NegativeInfinity & operator=(const NegativeInfinity &ninf)
Copy assignment operator (private & undefined)
I PositiveType
The positive infinity type.
Definition: Infinity.h:92
NegativeInfinity()
The default constructor of the NegativeInfinity class.
Definition: Infinity.h:165
void * operator&() const
Address operator (private & undefined)
NegativeInfinity< Infinity > NegativeType
The negative infinity type.
Definition: Infinity.h:535
const NegativeType operator-() const
Returns the negative infinity value for all built-in data types.
Definition: Infinity.h:833
Numerical limits of built-in data types.The Limits class provides numerical limits for the following ...
Definition: Limits.h:106
const Infinity inf
Global Infinity instance.The blaze::inf instance can be used wherever a built-in data type is expecte...
Definition: Infinity.h:1098
#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:78
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
Header file for basic type definitions.
const Infinity & operator+() const
Returns the positive infinity value for all built-in data types.
Definition: Infinity.h:821
Size type of the Blaze library.
bool equal(const T &rhs) const
Equality comparison to a built-in data type.
Definition: Infinity.h:856
Constraint on the data type.