All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Infinity.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_INFINITY_H_
23 #define _BLAZE_MATH_INFINITY_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
31 #include <blaze/util/Limits.h>
32 #include <blaze/util/Types.h>
33 
34 
35 namespace blaze {
36 
37 //=================================================================================================
38 //
39 // CLASS DEFINITION
40 //
41 //=================================================================================================
42 
43 //*************************************************************************************************
73 template< typename I > // Positive infinity type
75 {
76  public:
77  //**Type definitions****************************************************************************
78  typedef I PositiveType;
79  //**********************************************************************************************
80 
81  private:
82  //**Constructor*********************************************************************************
85  explicit inline NegativeInfinity();
86  // No explicitly declared copy constructor.
88  //**********************************************************************************************
89 
90  public:
91  //**Destructor**********************************************************************************
92  // No explicitly declared destructor.
93  //**********************************************************************************************
94 
95  //**Conversion operators************************************************************************
98  inline operator signed char() const;
99  inline operator char() const;
100  inline operator wchar_t() const;
101  inline operator short() const;
102  inline operator int() const;
103  inline operator long() const;
104 #if defined(_WIN64)
105  inline operator ptrdiff_t() const;
106 #endif
107  inline operator float() const;
108  inline operator double() const;
109  inline operator long double() const;
111  //**********************************************************************************************
112 
113  //**Utility functions***************************************************************************
116  template< typename T >
117  inline bool equal( const T& rhs ) const;
119  //**********************************************************************************************
120 
121  private:
122  //**Forbidden operations************************************************************************
126  void* operator&() const;
127 
128  //**********************************************************************************************
129 
130  //**Friend declarations*************************************************************************
132  friend class Infinity;
134  //**********************************************************************************************
135 };
136 //*************************************************************************************************
137 
138 
139 
140 
141 //=================================================================================================
142 //
143 // CONSTRUCTOR
144 //
145 //=================================================================================================
146 
147 //*************************************************************************************************
150 template< typename I > // Positive infinity type
152 {}
153 //*************************************************************************************************
154 
155 
156 
157 
158 //=================================================================================================
159 //
160 // CONVERSION OPERATORS
161 //
162 //=================================================================================================
163 
164 //*************************************************************************************************
169 template< typename I > // Positive infinity type
170 inline NegativeInfinity<I>::operator signed char() const
171 {
172  return Limits<signed char>::ninf();
173 }
174 //*************************************************************************************************
175 
176 
177 //*************************************************************************************************
182 template< typename I > // Positive infinity type
183 inline NegativeInfinity<I>::operator char() const
184 {
185  return Limits<char>::ninf();
186 }
187 //*************************************************************************************************
188 
189 
190 //*************************************************************************************************
195 template< typename I > // Positive infinity type
196 inline NegativeInfinity<I>::operator wchar_t() const
197 {
198  return Limits<wchar_t>::ninf();
199 }
200 //*************************************************************************************************
201 
202 
203 //*************************************************************************************************
208 template< typename I > // Positive infinity type
209 inline NegativeInfinity<I>::operator short() const
210 {
211  return Limits<short>::ninf();
212 }
213 //*************************************************************************************************
214 
215 
216 //*************************************************************************************************
221 template< typename I > // Positive infinity type
223 {
224  return Limits<int>::ninf();
225 }
226 //*************************************************************************************************
227 
228 
229 //*************************************************************************************************
234 template< typename I > // Positive infinity type
235 inline NegativeInfinity<I>::operator long() const
236 {
237  return Limits<long>::ninf();
238 }
239 //*************************************************************************************************
240 
241 
242 //*************************************************************************************************
243 #if defined(_WIN64)
244 
248 template< typename I > // Positive infinity type
250 {
251  return Limits<ptrdiff_t>::ninf();
252 }
253 #endif
254 //*************************************************************************************************
255 
256 
257 //*************************************************************************************************
262 template< typename I > // Positive infinity type
263 inline NegativeInfinity<I>::operator float() const
264 {
265  return Limits<float>::ninf();
266 }
267 //*************************************************************************************************
268 
269 
270 //*************************************************************************************************
275 template< typename I > // Positive infinity type
276 inline NegativeInfinity<I>::operator double() const
277 {
278  return Limits<double>::ninf();
279 }
280 //*************************************************************************************************
281 
282 
283 //*************************************************************************************************
288 template< typename I > // Positive infinity type
289 inline NegativeInfinity<I>::operator long double() const
290 {
291  return Limits<long double>::ninf();
292 }
293 //*************************************************************************************************
294 
295 
296 
297 
298 //=================================================================================================
299 //
300 // UTILITY FUNCTIONS
301 //
302 //=================================================================================================
303 
304 //*************************************************************************************************
311 template< typename I > // Positive infinity type
312 template< typename T > // Built-in data type
313 inline bool NegativeInfinity<I>::equal( const T& rhs ) const
314 {
316  return Limits<T>::ninf() == rhs;
317 }
318 //*************************************************************************************************
319 
320 
321 
322 
323 //=================================================================================================
324 //
325 // GLOBAL OPERATORS
326 //
327 //=================================================================================================
328 
329 //*************************************************************************************************
332 template< typename I, typename T >
333 inline bool operator==( const NegativeInfinity<I>& lhs, const T& rhs );
334 
335 template< typename I, typename T >
336 inline bool operator==( const T& lhs, const NegativeInfinity<I>& rhs );
337 
338 template< typename I, typename T >
339 inline bool operator!=( const NegativeInfinity<I>& lhs, const T& rhs );
340 
341 template< typename I, typename T >
342 inline bool operator!=( const T& lhs, const NegativeInfinity<I>& rhs );
344 //*************************************************************************************************
345 
346 
347 //*************************************************************************************************
358 template< typename I // Positive infinity type
359  , typename T > // Built-in data type
360 inline bool operator==( const NegativeInfinity<I>& lhs, const T& rhs )
361 {
362  return lhs.equal( rhs );
363 }
364 //*************************************************************************************************
365 
366 
367 //*************************************************************************************************
378 template< typename I // Positive infinity type
379  , typename T > // Built-in data type
380 inline bool operator==( const T& lhs, const NegativeInfinity<I>& rhs )
381 {
382  return rhs.equal( lhs );
383 }
384 //*************************************************************************************************
385 
386 
387 //*************************************************************************************************
398 template< typename I // Positive infinity type
399  , typename T > // Built-in data type
400 inline bool operator!=( const NegativeInfinity<I>& lhs, const T& rhs )
401 {
402  return !lhs.equal( rhs );
403 }
404 //*************************************************************************************************
405 
406 
407 //*************************************************************************************************
418 template< typename I // Positive infinity type
419  , typename T > // Built-in data type
420 inline bool operator!=( const T& lhs, const NegativeInfinity<I>& rhs )
421 {
422  return !rhs.equal( lhs );
423 }
424 //*************************************************************************************************
425 
426 
427 
428 
429 
430 
431 
432 
433 //=================================================================================================
434 //
435 // CLASS DEFINITION
436 //
437 //=================================================================================================
438 
439 //*************************************************************************************************
475 class Infinity
476 {
477  public:
478  //**Type definitions****************************************************************************
480  //**********************************************************************************************
481 
482  //**Constructor*********************************************************************************
485  explicit inline Infinity();
487  //**********************************************************************************************
488 
489  //**Destructor**********************************************************************************
490  // No explicitly declared destructor.
491  //**********************************************************************************************
492 
493  //**Conversion operators************************************************************************
496  inline operator unsigned char() const;
497  inline operator signed char() const;
498  inline operator char() const;
499  inline operator wchar_t() const;
500  inline operator unsigned short() const;
501  inline operator short() const;
502  inline operator unsigned int() const;
503  inline operator int() const;
504  inline operator unsigned long() const;
505  inline operator long() const;
506 #if defined(_WIN64)
507  inline operator size_t() const;
508  inline operator ptrdiff_t() const;
509 #endif
510  inline operator float() const;
511  inline operator double() const;
512  inline operator long double() const;
514  //**********************************************************************************************
515 
516  //**Arithmetic operators************************************************************************
519  inline const Infinity& operator+() const;
520  inline const NegativeType operator-() const;
522  //**********************************************************************************************
523 
524  //**Utility functions***************************************************************************
527  template< typename T >
528  inline bool equal( const T& rhs ) const;
530  //**********************************************************************************************
531 
532  private:
533  //**Forbidden operations************************************************************************
536  Infinity& operator=( const Infinity& inf );
537  void* operator&() const;
538 
539  //**********************************************************************************************
540 };
541 //*************************************************************************************************
542 
543 
544 
545 
546 //=================================================================================================
547 //
548 // CONSTRUCTOR
549 //
550 //=================================================================================================
551 
552 //*************************************************************************************************
556 {}
557 //*************************************************************************************************
558 
559 
560 
561 
562 //=================================================================================================
563 //
564 // CONVERSION OPERATORS
565 //
566 //=================================================================================================
567 
568 //*************************************************************************************************
573 inline Infinity::operator unsigned char() const
574 {
576 }
577 //*************************************************************************************************
578 
579 
580 //*************************************************************************************************
585 inline Infinity::operator char() const
586 {
587  return Limits<char>::inf();
588 }
589 //*************************************************************************************************
590 
591 
592 //*************************************************************************************************
597 inline Infinity::operator signed char() const
598 {
599  return Limits<signed char>::inf();
600 }
601 //*************************************************************************************************
602 
603 
604 //*************************************************************************************************
609 inline Infinity::operator wchar_t() const
610 {
611  return Limits<wchar_t>::inf();
612 }
613 //*************************************************************************************************
614 
615 
616 //*************************************************************************************************
621 inline Infinity::operator unsigned short() const
622 {
624 }
625 //*************************************************************************************************
626 
627 
628 //*************************************************************************************************
633 inline Infinity::operator short() const
634 {
635  return Limits<short>::inf();
636 }
637 //*************************************************************************************************
638 
639 
640 //*************************************************************************************************
645 inline Infinity::operator unsigned int() const
646 {
647  return Limits<unsigned int>::inf();
648 }
649 //*************************************************************************************************
650 
651 
652 //*************************************************************************************************
657 inline Infinity::operator int() const
658 {
659  return Limits<int>::inf();
660 }
661 //*************************************************************************************************
662 
663 
664 //*************************************************************************************************
669 inline Infinity::operator unsigned long() const
670 {
672 }
673 //*************************************************************************************************
674 
675 
676 //*************************************************************************************************
681 inline Infinity::operator long() const
682 {
683  return Limits<long>::inf();
684 }
685 //*************************************************************************************************
686 
687 
688 //*************************************************************************************************
689 #if defined(_WIN64)
690 
694 inline Infinity::operator size_t() const
695 {
696  return Limits<size_t>::inf();
697 }
698 #endif
699 //*************************************************************************************************
700 
701 
702 //*************************************************************************************************
703 #if defined(_WIN64)
704 
708 inline Infinity::operator ptrdiff_t() const
709 {
710  return Limits<ptrdiff_t>::inf();
711 }
712 #endif
713 //*************************************************************************************************
714 
715 
716 //*************************************************************************************************
721 inline Infinity::operator float() const
722 {
723  return Limits<float>::inf();
724 }
725 //*************************************************************************************************
726 
727 
728 //*************************************************************************************************
733 inline Infinity::operator double() const
734 {
735  return Limits<double>::inf();
736 }
737 //*************************************************************************************************
738 
739 
740 //*************************************************************************************************
745 inline Infinity::operator long double() const
746 {
747  return Limits<long double>::inf();
748 }
749 //*************************************************************************************************
750 
751 
752 
753 
754 //=================================================================================================
755 //
756 // ARITHMETIC OPERATORS
757 //
758 //=================================================================================================
759 
760 //*************************************************************************************************
765 inline const Infinity& Infinity::operator+() const
766 {
767  return *this;
768 }
769 //*************************************************************************************************
770 
771 
772 //*************************************************************************************************
778 {
779  return NegativeType();
780 }
781 //*************************************************************************************************
782 
783 
784 
785 
786 //=================================================================================================
787 //
788 // UTILITY FUNCTIONS
789 //
790 //=================================================================================================
791 
792 //*************************************************************************************************
799 template< typename T >
800 inline bool Infinity::equal( const T& rhs ) const
801 {
803  return Limits<T>::inf() == rhs;
804 }
805 //*************************************************************************************************
806 
807 
808 
809 
810 //=================================================================================================
811 //
812 // GLOBAL OPERATORS
813 //
814 //=================================================================================================
815 
816 //*************************************************************************************************
819 template< typename T >
820 inline bool operator==( const Infinity& lhs, const T& rhs );
821 
822 template< typename T >
823 inline bool operator==( const T& lhs, const Infinity& rhs );
824 
825 template< typename T >
826 inline bool operator!=( const Infinity& lhs, const T& rhs );
827 
828 template< typename T >
829 inline bool operator!=( const T& lhs, const Infinity& rhs );
831 //*************************************************************************************************
832 
833 
834 //*************************************************************************************************
845 template< typename T >
846 inline bool operator==( const Infinity& lhs, const T& rhs )
847 {
848  return lhs.equal( rhs );
849 }
850 //*************************************************************************************************
851 
852 
853 //*************************************************************************************************
864 template< typename T >
865 inline bool operator==( const T& lhs, const Infinity& rhs )
866 {
867  return rhs.equal( lhs );
868 }
869 //*************************************************************************************************
870 
871 
872 //*************************************************************************************************
883 template< typename T >
884 inline bool operator!=( const Infinity& lhs, const T& rhs )
885 {
886  return !lhs.equal( rhs );
887 }
888 //*************************************************************************************************
889 
890 
891 //*************************************************************************************************
902 template< typename T >
903 inline bool operator!=( const T& lhs, const Infinity& rhs )
904 {
905  return !rhs.equal( lhs );
906 }
907 //*************************************************************************************************
908 
909 
910 
911 
912 //=================================================================================================
913 //
914 // GLOBAL INFINITY VALUE
915 //
916 //=================================================================================================
917 
918 //*************************************************************************************************
926 const Infinity inf;
927 //*************************************************************************************************
928 
929 } // namespace blaze
930 
931 #endif