Blaze 3.9
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
45#include <blaze/util/Limits.h>
46#include <blaze/util/Types.h>
47
48
49namespace blaze {
50
51//=================================================================================================
52//
53// CLASS DEFINITION
54//
55//=================================================================================================
56
57//*************************************************************************************************
87template< typename I > // Positive infinity type
89{
90 public:
91 //**Type definitions****************************************************************************
92 using PositiveType = I;
93 //**********************************************************************************************
94
95 private:
96 //**Constructors********************************************************************************
99 constexpr NegativeInfinity();
100 NegativeInfinity( const NegativeInfinity& ) = default;
102 //**********************************************************************************************
103
104 public:
105 //**Destructor**********************************************************************************
108 ~NegativeInfinity() = default;
110 //**********************************************************************************************
111
112 //**Conversion operators************************************************************************
115 constexpr operator signed char() const;
116 constexpr operator char() const;
117 constexpr operator wchar_t() const;
118 constexpr operator short() const;
119 constexpr operator int() const;
120 constexpr operator long() const;
121#if BLAZE_WIN32_PLATFORM || BLAZE_WIN64_PLATFORM
122 constexpr operator ptrdiff_t() const;
123#endif
124 constexpr operator float() const;
125 constexpr operator double() const;
126 constexpr operator long double() const;
128 //**********************************************************************************************
129
130 //**Utility functions***************************************************************************
133 template< typename T >
134 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//*************************************************************************************************
167template< typename I > // Positive infinity type
169{}
170//*************************************************************************************************
171
172
173
174
175//=================================================================================================
176//
177// CONVERSION OPERATORS
178//
179//=================================================================================================
180
181//*************************************************************************************************
186template< typename I > // Positive infinity type
187constexpr NegativeInfinity<I>::operator signed char() const
188{
190}
191//*************************************************************************************************
192
193
194//*************************************************************************************************
199template< typename I > // Positive infinity type
200constexpr NegativeInfinity<I>::operator char() const
201{
202 return Limits<char>::ninf();
203}
204//*************************************************************************************************
205
206
207//*************************************************************************************************
212template< typename I > // Positive infinity type
213constexpr NegativeInfinity<I>::operator wchar_t() const
214{
215 return Limits<wchar_t>::ninf();
216}
217//*************************************************************************************************
218
219
220//*************************************************************************************************
225template< typename I > // Positive infinity type
226constexpr NegativeInfinity<I>::operator short() const
227{
228 return Limits<short>::ninf();
229}
230//*************************************************************************************************
231
232
233//*************************************************************************************************
238template< typename I > // Positive infinity type
239constexpr NegativeInfinity<I>::operator int() const
240{
241 return Limits<int>::ninf();
242}
243//*************************************************************************************************
244
245
246//*************************************************************************************************
251template< typename I > // Positive infinity type
252constexpr NegativeInfinity<I>::operator long() const
253{
254 return Limits<long>::ninf();
255}
256//*************************************************************************************************
257
258
259//*************************************************************************************************
260#if BLAZE_WIN32_PLATFORM || BLAZE_WIN64_PLATFORM
265template< typename I > // Positive infinity type
266constexpr NegativeInfinity<I>::operator ptrdiff_t() const
267{
269}
270#endif
271//*************************************************************************************************
272
273
274//*************************************************************************************************
279template< typename I > // Positive infinity type
280constexpr NegativeInfinity<I>::operator float() const
281{
282 return Limits<float>::ninf();
283}
284//*************************************************************************************************
285
286
287//*************************************************************************************************
292template< typename I > // Positive infinity type
293constexpr NegativeInfinity<I>::operator double() const
294{
295 return Limits<double>::ninf();
296}
297//*************************************************************************************************
298
299
300//*************************************************************************************************
305template< typename I > // Positive infinity type
306constexpr NegativeInfinity<I>::operator long double() const
307{
309}
310//*************************************************************************************************
311
312
313
314
315//=================================================================================================
316//
317// UTILITY FUNCTIONS
318//
319//=================================================================================================
320
321//*************************************************************************************************
328template< typename I > // Positive infinity type
329template< typename T > // Built-in data type
330constexpr 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//*************************************************************************************************
349template< typename I1, typename I2 >
350constexpr bool operator==( const NegativeInfinity<I1>& lhs, const NegativeInfinity<I2>& rhs );
351
352template< typename I, typename T >
353constexpr bool operator==( const NegativeInfinity<I>& lhs, const T& rhs );
354
355template< typename I, typename T >
356constexpr bool operator==( const T& lhs, const NegativeInfinity<I>& rhs );
357
358template< typename I1, typename I2 >
359constexpr bool operator!=( const NegativeInfinity<I1>& lhs, const NegativeInfinity<I2>& rhs );
360
361template< typename I, typename T >
362constexpr bool operator!=( const NegativeInfinity<I>& lhs, const T& rhs );
363
364template< typename I, typename T >
365constexpr bool operator!=( const T& lhs, const NegativeInfinity<I>& rhs );
367//*************************************************************************************************
368
369
370//*************************************************************************************************
376template< typename I1 // Left-hand side positive infinity type
377 , typename I2 > // Right-hand side positive infinity type
378constexpr bool operator==( const NegativeInfinity<I1>& /*lhs*/, const NegativeInfinity<I2>& /*rhs*/ )
379{
380 return true;
381}
382//*************************************************************************************************
383
384
385//*************************************************************************************************
396template< typename I // Positive infinity type
397 , typename T > // Built-in data type
398constexpr bool operator==( const NegativeInfinity<I>& lhs, const T& rhs )
399{
400 return lhs.equal( rhs );
401}
402//*************************************************************************************************
403
404
405//*************************************************************************************************
416template< typename I // Positive infinity type
417 , typename T > // Built-in data type
418constexpr bool operator==( const T& lhs, const NegativeInfinity<I>& rhs )
419{
420 return rhs.equal( lhs );
421}
422//*************************************************************************************************
423
424
425//*************************************************************************************************
431template< typename I1 // Left-hand side positive infinity type
432 , typename I2 > // Right-hand side positive infinity type
433constexpr bool operator!=( const NegativeInfinity<I1>& /*lhs*/, const NegativeInfinity<I2>& /*rhs*/ )
434{
435 return false;
436}
437//*************************************************************************************************
438
439
440//*************************************************************************************************
451template< typename I // Positive infinity type
452 , typename T > // Built-in data type
453constexpr bool operator!=( const NegativeInfinity<I>& lhs, const T& rhs )
454{
455 return !lhs.equal( rhs );
456}
457//*************************************************************************************************
458
459
460//*************************************************************************************************
471template< typename I // Positive infinity type
472 , typename T > // Built-in data type
473constexpr 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//*************************************************************************************************
529{
530 public:
531 //**Type definitions****************************************************************************
533 //**********************************************************************************************
534
535 //**Constructors********************************************************************************
538 constexpr Infinity();
539 Infinity( const Infinity& ) = default;
541 //**********************************************************************************************
542
543 //**Destructor**********************************************************************************
546 ~Infinity() = default;
548 //**********************************************************************************************
549
550 //**Conversion operators************************************************************************
553 constexpr operator unsigned char() const;
554 constexpr operator signed char() const;
555 constexpr operator char() const;
556 constexpr operator wchar_t() const;
557 constexpr operator unsigned short() const;
558 constexpr operator short() const;
559 constexpr operator unsigned int() const;
560 constexpr operator int() const;
561 constexpr operator unsigned long() const;
562 constexpr operator long() const;
563#if BLAZE_WIN32_PLATFORM || BLAZE_WIN64_PLATFORM
564 constexpr operator size_t() const;
565 constexpr operator ptrdiff_t() const;
566#endif
567 constexpr operator float() const;
568 constexpr operator double() const;
569 constexpr operator long double() const;
571 //**********************************************************************************************
572
573 //**Arithmetic operators************************************************************************
576 constexpr const Infinity& operator+() const;
577 constexpr const NegativeType operator-() const;
579 //**********************************************************************************************
580
581 //**Utility functions***************************************************************************
584 template< typename T >
585 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//*************************************************************************************************
612{}
613//*************************************************************************************************
614
615
616
617
618//=================================================================================================
619//
620// CONVERSION OPERATORS
621//
622//=================================================================================================
623
624//*************************************************************************************************
629constexpr Infinity::operator unsigned char() const
630{
632}
633//*************************************************************************************************
634
635
636//*************************************************************************************************
641constexpr Infinity::operator char() const
642{
643 return Limits<char>::inf();
644}
645//*************************************************************************************************
646
647
648//*************************************************************************************************
653constexpr Infinity::operator signed char() const
654{
656}
657//*************************************************************************************************
658
659
660//*************************************************************************************************
665constexpr Infinity::operator wchar_t() const
666{
667 return Limits<wchar_t>::inf();
668}
669//*************************************************************************************************
670
671
672//*************************************************************************************************
677constexpr Infinity::operator unsigned short() const
678{
680}
681//*************************************************************************************************
682
683
684//*************************************************************************************************
689constexpr Infinity::operator short() const
690{
691 return Limits<short>::inf();
692}
693//*************************************************************************************************
694
695
696//*************************************************************************************************
701constexpr Infinity::operator unsigned int() const
702{
704}
705//*************************************************************************************************
706
707
708//*************************************************************************************************
713constexpr Infinity::operator int() const
714{
715 return Limits<int>::inf();
716}
717//*************************************************************************************************
718
719
720//*************************************************************************************************
725constexpr Infinity::operator unsigned long() const
726{
728}
729//*************************************************************************************************
730
731
732//*************************************************************************************************
737constexpr Infinity::operator long() const
738{
739 return Limits<long>::inf();
740}
741//*************************************************************************************************
742
743
744//*************************************************************************************************
745#if BLAZE_WIN32_PLATFORM || BLAZE_WIN64_PLATFORM
750constexpr Infinity::operator size_t() const
751{
752 return Limits<size_t>::inf();
753}
754#endif
755//*************************************************************************************************
756
757
758//*************************************************************************************************
759#if BLAZE_WIN32_PLATFORM || BLAZE_WIN64_PLATFORM
764constexpr Infinity::operator ptrdiff_t() const
765{
766 return Limits<ptrdiff_t>::inf();
767}
768#endif
769//*************************************************************************************************
770
771
772//*************************************************************************************************
777constexpr Infinity::operator float() const
778{
779 return Limits<float>::inf();
780}
781//*************************************************************************************************
782
783
784//*************************************************************************************************
789constexpr Infinity::operator double() const
790{
791 return Limits<double>::inf();
792}
793//*************************************************************************************************
794
795
796//*************************************************************************************************
801constexpr Infinity::operator long double() const
802{
804}
805//*************************************************************************************************
806
807
808
809
810//=================================================================================================
811//
812// ARITHMETIC OPERATORS
813//
814//=================================================================================================
815
816//*************************************************************************************************
821constexpr 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//*************************************************************************************************
855template< typename T >
856constexpr 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//*************************************************************************************************
875constexpr bool operator==( const Infinity& lhs, const Infinity& rhs );
876
877template< typename I >
878constexpr bool operator==( const Infinity& lhs, const NegativeInfinity<I>& rhs );
879
880template< typename I >
881constexpr bool operator==( const NegativeInfinity<I>& lhs, const Infinity& rhs );
882
883template< typename T >
884constexpr bool operator==( const Infinity& lhs, const T& rhs );
885
886template< typename T >
887constexpr bool operator==( const T& lhs, const Infinity& rhs );
888
889constexpr bool operator!=( const Infinity& lhs, const Infinity& rhs );
890
891template< typename I >
892constexpr bool operator!=( const Infinity& lhs, const NegativeInfinity<I>& rhs );
893
894template< typename I >
895constexpr bool operator!=( const NegativeInfinity<I>& lhs, const Infinity& rhs );
896
897template< typename T >
898constexpr bool operator!=( const Infinity& lhs, const T& rhs );
899
900template< typename T >
901constexpr bool operator!=( const T& lhs, const Infinity& rhs );
903//*************************************************************************************************
904
905
906//*************************************************************************************************
912constexpr bool operator==( const Infinity& /*lhs*/, const Infinity& /*rhs*/ )
913{
914 return true;
915}
916//*************************************************************************************************
917
918
919//*************************************************************************************************
925template< typename I > // Positive infinity type
926constexpr bool operator==( const Infinity& /*lhs*/, const NegativeInfinity<I>& /*rhs*/ )
927{
928 return false;
929}
930//*************************************************************************************************
931
932
933//*************************************************************************************************
939template< typename I > // Positive infinity type
940constexpr bool operator==( const NegativeInfinity<I>& /*lhs*/, const Infinity& /*rhs*/ )
941{
942 return false;
943}
944//*************************************************************************************************
945
946
947//*************************************************************************************************
958template< typename T >
959constexpr bool operator==( const Infinity& lhs, const T& rhs )
960{
961 return lhs.equal( rhs );
962}
963//*************************************************************************************************
964
965
966//*************************************************************************************************
977template< typename T >
978constexpr bool operator==( const T& lhs, const Infinity& rhs )
979{
980 return rhs.equal( lhs );
981}
982//*************************************************************************************************
983
984
985//*************************************************************************************************
991constexpr bool operator!=( const Infinity& /*lhs*/, const Infinity& /*rhs*/ )
992{
993 return false;
994}
995//*************************************************************************************************
996
997
998//*************************************************************************************************
1004template< typename I > // Positive infinity type
1005constexpr bool operator!=( const Infinity& /*lhs*/, const NegativeInfinity<I>& /*rhs*/ )
1006{
1007 return true;
1008}
1009//*************************************************************************************************
1010
1011
1012//*************************************************************************************************
1018template< typename I > // Positive infinity type
1019constexpr bool operator!=( const NegativeInfinity<I>& /*lhs*/, const Infinity& /*rhs*/ )
1020{
1021 return true;
1022}
1023//*************************************************************************************************
1024
1025
1026//*************************************************************************************************
1037template< typename T >
1038constexpr bool operator!=( const Infinity& lhs, const T& rhs )
1039{
1040 return !lhs.equal( rhs );
1041}
1042//*************************************************************************************************
1043
1044
1045//*************************************************************************************************
1056template< typename T >
1057constexpr 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//*************************************************************************************************
1080constexpr Infinity inf;
1081//*************************************************************************************************
1082
1083} // namespace blaze
1084
1085#endif
Constraint on the data type.
Numerical limits of built-in data types.
Platform-specific system settings.
Positive infinity for built-in data types.
Definition: Infinity.h:529
constexpr Infinity()
The default constructor of the Infinity class.
Definition: Infinity.h:611
constexpr const Infinity & operator+() const
Returns the positive infinity value for all built-in data types.
Definition: Infinity.h:821
constexpr bool equal(const T &rhs) const
Equality comparison to a built-in data type.
Definition: Infinity.h:856
constexpr const NegativeType operator-() const
Returns the negative infinity value for all built-in data types.
Definition: Infinity.h:833
NegativeInfinity< Infinity > NegativeType
The negative infinity type.
Definition: Infinity.h:532
Negative infinity for built-in data types.
Definition: Infinity.h:89
constexpr bool equal(const T &rhs) const
Equality comparison to a built-in data type.
Definition: Infinity.h:330
I PositiveType
The positive infinity type.
Definition: Infinity.h:92
constexpr NegativeInfinity()
The default constructor of the NegativeInfinity class.
Definition: Infinity.h:168
Pointer difference type of the Blaze library.
#define BLAZE_CONSTRAINT_MUST_BE_BUILTIN_TYPE(T)
Constraint on the data type.
Definition: Builtin.h:60
constexpr Infinity inf
Global Infinity instance.
Definition: Infinity.h:1080
constexpr bool operator!=(const T &lhs, const Infinity &rhs)
Inequality comparison between a built-in data type and an Infinity object.
Definition: Infinity.h:1057
constexpr bool operator==(const T &lhs, const Infinity &rhs)
Equality comparison between a built-in data type and an Infinity object.
Definition: Infinity.h:978
Numerical limits of built-in data types.
Definition: Limits.h:108
Header file for basic type definitions.