HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SYS_Decimal128.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SYS_Decimal128.h (SYS Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __SYS_DECIMAL128_H_INCLUDED__
12 #define __SYS_DECIMAL128_H_INCLUDED__
13 
14 #include "SYS_API.h"
15 #ifndef __SYS_Types__
16 #error This file must be included from SYS_Types.h
17 #endif
18 
19 #include "SYS_Compiler.h"
20 #include <iosfwd>
21 
22 
23 /// Decimal128 floating point class (IEEE 754-2008)
25 {
26 public:
27  /// Default constructor, leaves value uninitialized
28  SYS_Decimal128() = default;
29 
30  explicit SYS_Decimal128(int32 v);
31  explicit SYS_Decimal128(uint32 v);
32  explicit SYS_Decimal128(fpreal32 v);
33  explicit SYS_Decimal128(fpreal64 v);
34  explicit SYS_Decimal128(const char *str);
35 
36  /// Conversion to other type
37  /// @{
38  operator int32() const;
39  operator uint32() const;
40  operator fpreal32() const;
41  operator fpreal64() const;
42  /// @}
43 
44  /// Round to nearest integer, 0.6 rounds up
45  int32 roundedInt() const;
46 
47  /// Unary minus
48  SYS_Decimal128 operator-() const;
49 
50  /// Assignment
51  /// @{
52  SYS_Decimal128& operator=(int32 v);
53  SYS_Decimal128& operator=(uint32 v);
54  SYS_Decimal128& operator=(fpreal32 v);
55  SYS_Decimal128& operator=(fpreal64 v);
56  /// @}
57 
58  /// Arithmetic Assignment
59  /// @{
64  /// @}
65 
66  /// Set to zero
67  void zero();
68 
69  /// Classification
70  /// @{
71  bool isCanonical() const;
72  bool isFinite() const;
73  bool isInfinite() const;
74  bool isInteger() const;
75  bool isNan() const;
76  bool isNegative() const;
77  bool isNormal() const;
78  bool isPositive() const;
79  bool isZero() const;
80  /// @}
81 
82  /// Determine number of significant digits
83  uint numDigits() const;
84 
85  /// Comparison Operators
86  /// @{
87  bool operator==(const SYS_Decimal128 &v) const;
88  bool operator!=(const SYS_Decimal128 &v) const
89  { return !(*this == v); }
90  bool operator<(const SYS_Decimal128 &v) const;
91  bool operator<=(const SYS_Decimal128 &v) const;
92  bool operator>(const SYS_Decimal128 &v) const;
93  bool operator>=(const SYS_Decimal128 &v) const;
94  /// @}
95 
96  /// Maximum string length+1
97  static const int NUMBUF = 43;
98 
99  /// Conversion to string, buffer must contain at least NUMBUF bytes
100  void toString(char *str) const;
101 
102  /// Conversion from string
103  void fromString(const char *str);
104 
105 private:
106  SYS_MAYBE_UNUSED_MEMBER uint8 myValue[16];
107 };
108 
109 /// Binary arithmetic operators
110 /// @{
112  const SYS_Decimal128 &y);
114  const SYS_Decimal128 &y);
116  const SYS_Decimal128 &y);
118  const SYS_Decimal128 &y);
119 /// @}
120 
121 /// Stream I/O
122 /// @{
123 SYS_API std::ostream& operator<<(std::ostream &os, const SYS_Decimal128 &v);
124 SYS_API std::istream& operator>>(std::istream &is, SYS_Decimal128 &v);
125 /// @}
126 
127 /// String formatting
128 /// @{
129 SYS_API size_t format(char *buffer, size_t buffer_size, const SYS_Decimal128 &v);
130 /// @}
131 
132 //////////////////////////////////////////////////////////////////////////////
133 //
134 // Inline implementations
135 //
136 
137 inline
139 {
140  operator=(v);
141 }
142 
143 inline
145 {
146  operator=(v);
147 }
148 
149 inline
151 {
152  operator=(v);
153 }
154 
155 inline
157 {
158  operator=(v);
159 }
160 
161 inline
163 {
164  fromString(str);
165 }
166 
167 #endif // __SYS_DECIMAL128_H_INCLUDED__
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
Definition: Mat3.h:575
OIIO_FORCEINLINE const vint4 & operator/=(vint4 &a, const vint4 &b)
Definition: simd.h:4438
int int32
Definition: SYS_Types.h:39
SYS_API size_t format(char *buffer, size_t buffer_size, const SYS_Decimal128 &v)
SYS_API SYS_Decimal128 operator/(const SYS_Decimal128 &x, const SYS_Decimal128 &y)
SYS_API std::ostream & operator<<(std::ostream &os, const SYS_Decimal128 &v)
Mat3< typename promote< T0, T1 >::type > operator+(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
Definition: Mat3.h:591
float fpreal32
Definition: SYS_Types.h:200
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:368
OIIO_FORCEINLINE vbool4 operator>=(const vint4 &a, const vint4 &b)
Definition: simd.h:4577
GLint GLenum GLint x
Definition: glcorearb.h:409
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
OIIO_FORCEINLINE vbool4 operator>(const vint4 &a, const vint4 &b)
Definition: simd.h:4561
OIIO_FORCEINLINE vbool4 operator<=(const vint4 &a, const vint4 &b)
Definition: simd.h:4581
Definition: core.h:760
Mat3< typename promote< T0, T1 >::type > operator-(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
Definition: Mat3.h:601
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
Definition: simd.h:4369
SYS_Decimal128()=default
Default constructor, leaves value uninitialized.
const GLdouble * v
Definition: glcorearb.h:837
bool isInfinite(const float x)
Return true if x is an infinity value (either positive infinity or negative infinity).
Definition: Math.h:386
void fromString(const char *str)
Conversion from string.
bool operator!=(const SYS_Decimal128 &v) const
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
bool isNan(const float x)
Return true if x is a NaN (Not-A-Number) value.
Definition: Math.h:396
IMATH_HOSTDEVICE const Vec2< S > & operator*=(Vec2< S > &v, const Matrix22< T > &m) IMATH_NOEXCEPT
Vector-matrix multiplication: v *= m.
Definition: ImathMatrix.h:4660
Decimal128 floating point class (IEEE 754-2008)
unsigned int uint32
Definition: SYS_Types.h:40
SYS_API std::istream & operator>>(std::istream &is, SYS_Decimal128 &v)
OIIO_FORCEINLINE const vint4 & operator-=(vint4 &a, const vint4 &b)
Definition: simd.h:4392
#define SYS_API
Definition: SYS_API.h:11
SYS_API SYS_Decimal128 operator-(const SYS_Decimal128 &x, const SYS_Decimal128 &y)
#define SYS_MAYBE_UNUSED_MEMBER
Definition: SYS_Compiler.h:79
ImageBuf OIIO_API zero(ROI roi, int nthreads=0)
unsigned int uint
Definition: SYS_Types.h:45
GLint y
Definition: glcorearb.h:103
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:338
bool isFinite(const float x)
Return true if x is finite.
Definition: Math.h:376
SYS_Decimal128 & operator=(int32 v)