- Timestamp:
- Sep 29, 2011, 9:10:00 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/real.cpp
r995 r997 441 441 { 442 442 return !(*this < x); 443 } 444 445 bool real::operator !() const 446 { 447 return !(bool)*this; 448 } 449 450 real::operator bool() const 451 { 452 /* A real is "true" if it is non-zero (exponent is non-zero) AND 453 * not NaN (exponent is not full bits OR higher order mantissa is zero) */ 454 uint32_t exponent = m_signexp << 1; 455 return exponent && (~exponent || m_mantissa[0] == 0); 443 456 } 444 457 -
trunk/src/real.h
r995 r997 59 59 bool operator >=(real const &x) const; 60 60 61 bool operator !() const; 62 operator bool() const; 63 61 64 friend real fabs(real const &x); 62 65 -
trunk/test/math/remez.cpp
r996 r997 22 22 static int const ORDER = 8; 23 23 24 static real compute_pi()25 {26 /* Approximate Pi using Machin's formula: 16*atan(1/5)-4*atan(1/239) */27 real sum = 0.0, x0 = 5.0, x1 = 239.0;28 real const m0 = -x0 * x0, m1 = -x1 * x1, r16 = 16.0, r4 = 4.0;29 30 /* Degree 240 is required for 512-bit mantissa precision */31 for (int i = 1; i < 240; i += 2)32 {33 sum += r16 / (x0 * (real)i) - r4 / (x1 * (real)i);34 x0 *= m0;35 x1 *= m1;36 }37 return sum;38 }39 40 24 /* The function we want to approximate */ 41 25 static real myfun(real const &x) 42 26 { 43 static real const half_pi = compute_pi() * (real)0.5;44 27 static real const one = 1.0; 45 if ( x == (real)0.0 || x == (real)-0.0)46 return half_pi;47 return sin(x * half_pi) / x;28 if (!x) 29 return real::R_PI_2; 30 return sin(x * real::R_PI_2) / x; 48 31 //return cos(x) - one; 49 32 //return exp(x); -
trunk/test/unit/real.cpp
r994 r997 177 177 LOLUNIT_ASSERT_EQUAL((double)(a3 << -7), 0.0); 178 178 } 179 180 LOLUNIT_TEST(Bool) 181 { 182 real a = 0.0; 183 LOLUNIT_ASSERT(!a); 184 185 a = -0.0; 186 LOLUNIT_ASSERT(!a); 187 188 a = 1234.0; 189 LOLUNIT_ASSERT(a); 190 LOLUNIT_ASSERT(!!a); 191 192 a = -1234.0; 193 LOLUNIT_ASSERT(a); 194 LOLUNIT_ASSERT(!!a); 195 } 179 196 }; 180 197
Note: See TracChangeset
for help on using the changeset viewer.