Changeset 998
 Timestamp:
 Oct 3, 2011, 1:36:16 AM (10 years ago)
 Location:
 trunk
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/real.cpp
r997 r998 324 324 real real::operator /(real const &x) const 325 325 { 326 return *this * fres(x);326 return *this * re(x); 327 327 } 328 328 … … 456 456 } 457 457 458 real fres(real const &x)458 real re(real const &x) 459 459 { 460 460 if (!(x.m_signexp << 1)) … … 742 742 } 743 743 744 real const real::R_E = exp((real)1.0); 745 real const real::R_LOG2E = (real)1.0 / R_LN2; 746 real const real::R_LOG10E = (real)1.0 / R_LN10; 747 real const real::R_LN2 = log((real)2.0); 748 real const real::R_LN10 = log((real)10.0); 744 real const real::R_0 = (real)0.0; 745 real const real::R_1 = (real)1.0; 746 real const real::R_2 = (real)2.0; 747 real const real::R_10 = (real)10.0; 748 749 real const real::R_E = exp(R_1); 750 real const real::R_LN2 = log(R_2); 751 real const real::R_LN10 = log(R_10); 752 real const real::R_LOG2E = re(R_LN2); 753 real const real::R_LOG10E = re(R_LN10); 749 754 real const real::R_PI = fast_pi(); 750 755 real const real::R_PI_2 = R_PI >> 1; 751 756 real const real::R_PI_4 = R_PI >> 2; 752 real const real::R_1_PI = (real)1.0 / R_PI;757 real const real::R_1_PI = re(R_PI); 753 758 real const real::R_2_PI = R_1_PI << 1; 754 real const real::R_2_SQRTPI = (real)2.0 / sqrt(R_PI);755 real const real::R_SQRT2 = sqrt( (real)2.0);759 real const real::R_2_SQRTPI = re(sqrt(R_PI)) << 1; 760 real const real::R_SQRT2 = sqrt(R_2); 756 761 real const real::R_SQRT1_2 = R_SQRT2 >> 1; 757 762 
trunk/src/real.h
r997 r998 64 64 friend real fabs(real const &x); 65 65 66 friend real fres(real const &x);66 friend real re(real const &x); 67 67 friend real sqrt(real const &x); 68 68 friend real log(real const &x); … … 73 73 74 74 void print(int ndigits = 150) const; 75 76 static real const R_0; 77 static real const R_1; 78 static real const R_2; 79 static real const R_10; 75 80 76 81 static real const R_E; 
trunk/test/unit/real.cpp
r997 r998 23 23 LOLUNIT_FIXTURE(RealTest) 24 24 { 25 LOLUNIT_TEST(Constants) 26 { 27 double a0 = real::R_0; 28 double a1 = real::R_1; 29 double a2 = real::R_2; 30 double a10 = real::R_10; 31 32 LOLUNIT_ASSERT_EQUAL(a0, 0.0); 33 LOLUNIT_ASSERT_EQUAL(a1, 1.0); 34 LOLUNIT_ASSERT_EQUAL(a2, 2.0); 35 LOLUNIT_ASSERT_EQUAL(a10, 10.0); 36 37 double b0 = log(real::R_E); 38 LOLUNIT_ASSERT_EQUAL(b0, 1.0); 39 40 double b1 = exp(re(real::R_LOG2E)); 41 LOLUNIT_ASSERT_EQUAL(b1, 2.0); 42 43 double b2 = exp(re(real::R_LOG10E)); 44 LOLUNIT_ASSERT_EQUAL(b2, 10.0); 45 46 double b3 = exp(real::R_LN2); 47 LOLUNIT_ASSERT_EQUAL(b3, 2.0); 48 49 double b4 = exp(real::R_LN10); 50 LOLUNIT_ASSERT_EQUAL(b4, 10.0); 51 52 double b5 = sin(real::R_PI); 53 double b6 = cos(real::R_PI); 54 LOLUNIT_ASSERT_DOUBLES_EQUAL(b5, 0.0, 1e100); 55 LOLUNIT_ASSERT_EQUAL(b6, 1.0); 56 57 double b7 = sin(real::R_PI_2); 58 double b8 = cos(real::R_PI_2); 59 LOLUNIT_ASSERT_EQUAL(b7, 1.0); 60 LOLUNIT_ASSERT_DOUBLES_EQUAL(b8, 0.0, 1e100); 61 62 double b9 = sin(real::R_PI_4) * sin(real::R_PI_4); 63 double b10 = cos(real::R_PI_4) * cos(real::R_PI_4); 64 LOLUNIT_ASSERT_EQUAL(b9, 0.5); 65 LOLUNIT_ASSERT_EQUAL(b10, 0.5); 66 } 67 25 68 LOLUNIT_TEST(FloatToReal) 26 69 {
Note: See TracChangeset
for help on using the changeset viewer.