diff --git a/src/CLR/CorLib/corlib_native_System_Math.cpp b/src/CLR/CorLib/corlib_native_System_Math.cpp index 14bc75d741..eb89bd2832 100644 --- a/src/CLR/CorLib/corlib_native_System_Math.cpp +++ b/src/CLR/CorLib/corlib_native_System_Math.cpp @@ -18,7 +18,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().s4; - float res = System::Math::Abs( d ); + float res = fabs( d ); stack.SetResult_I4( res ); @@ -36,9 +36,9 @@ NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - float y = stack.Arg0().NumericByRefConst().s4; - float x = stack.Arg1().NumericByRefConst().s4; - float res = System::Math::Max( y, x ); + float x = stack.Arg0().NumericByRefConst().s4; + float y = stack.Arg1().NumericByRefConst().s4; + float res = x >= y ? x : y; stack.SetResult_I4( res ); @@ -56,9 +56,9 @@ NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - float y = stack.Arg0().NumericByRefConst().r4; - float x = stack.Arg1().NumericByRefConst().r4; - float res = System::Math::Max( y, x ); + float x = stack.Arg0().NumericByRefConst().r4; + float y = stack.Arg1().NumericByRefConst().r4; + float res = x >= y ? x : y; stack.SetResult_R4( res ); @@ -74,9 +74,9 @@ NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - double y = stack.Arg0().NumericByRefConst().r8; - double x = stack.Arg1().NumericByRefConst().r8; - double res = System::Math::Max( y, x ); + double x = stack.Arg0().NumericByRefConst().r8; + double y = stack.Arg1().NumericByRefConst().r8; + double res = x >= y ? x : y; stack.SetResult_R8( res ); @@ -96,9 +96,9 @@ NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - float y = stack.Arg0().NumericByRefConst().s4; - float x = stack.Arg1().NumericByRefConst().s4; - float res = System::Math::Min( y, x ); + float x = stack.Arg0().NumericByRefConst().s4; + float y = stack.Arg1().NumericByRefConst().s4; + float res = x <= y ? x : y; stack.SetResult_I4( res ); @@ -116,9 +116,9 @@ NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - float y = stack.Arg0().NumericByRefConst().r4; - float x = stack.Arg1().NumericByRefConst().r4; - float res = System::Math::Min( y, x ); + float x = stack.Arg0().NumericByRefConst().r4; + float y = stack.Arg1().NumericByRefConst().r4; + float res = x <= y ? x : y; stack.SetResult_R4( res ); @@ -134,9 +134,9 @@ NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - double y = stack.Arg0().NumericByRefConst().r8; - double x = stack.Arg1().NumericByRefConst().r8; - double res = System::Math::Min( y, x ); + double x = stack.Arg0().NumericByRefConst().r8; + double y = stack.Arg1().NumericByRefConst().r8; + double res = x <= y ? x : y; stack.SetResult_R8( res ); @@ -155,7 +155,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Abs( d ); + double res = fabs( d ); stack.SetResult_R8( res ); @@ -176,7 +176,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Abs( d ); + float res = fabs( d ); stack.SetResult_R4( res ); @@ -193,7 +193,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Acos( d ); + double res = acos( d ); stack.SetResult_R8( res ); @@ -214,7 +214,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Acos( d ); + float res = acos( d ); stack.SetResult_R4( res ); @@ -231,7 +231,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Asin( d ); + double res = asin( d ); stack.SetResult_R8( res ); @@ -252,7 +252,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Asin( d ); + float res = asin( d ); stack.SetResult_R4( res ); @@ -269,7 +269,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Atan( d ); + double res = atan( d ); stack.SetResult_R8( res ); @@ -290,7 +290,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Atan( d ); + float res = atan( d ); stack.SetResult_R4( res ); @@ -306,9 +306,9 @@ NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - double y = stack.Arg0().NumericByRefConst().r8; - double x = stack.Arg1().NumericByRefConst().r8; - double res = System::Math::Atan2( y, x ); + double x = stack.Arg0().NumericByRefConst().r8; + double y = stack.Arg1().NumericByRefConst().r8; + double res = atan2( x, y ); stack.SetResult_R8( res ); @@ -328,9 +328,9 @@ NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - float y = stack.Arg0().NumericByRefConst().r4; - float x = stack.Arg1().NumericByRefConst().r4; - float res = System::Math::Atan2( y, x ); + float x = stack.Arg0().NumericByRefConst().r4; + float y = stack.Arg1().NumericByRefConst().r4; + float res = atan2( x, y ); stack.SetResult_R4( res ); @@ -347,7 +347,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Ceiling( d ); + double res = ceil( d ); stack.SetResult_R8( res ); @@ -369,7 +369,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Ceiling( d ); + float res = ceil( d ); stack.SetResult_R4( res ); @@ -387,7 +387,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Cos( d ); + double res = cos( d ); stack.SetResult_R8( res ); @@ -408,7 +408,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Cos( d ); + float res = cos( d ); stack.SetResult_R4( res ); @@ -425,7 +425,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Cosh( d ); + double res = cosh( d ); stack.SetResult_R8( res ); @@ -446,7 +446,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Cosh( d ); + float res = cosh( d ); stack.SetResult_R4( res ); @@ -464,7 +464,7 @@ double x = stack.Arg0().NumericByRefConst().r8; double y = stack.Arg1().NumericByRefConst().r8; - double res = System::Math::IEEERemainder(x, y); + double res = remainder(x, y); stack.SetResult_R8( res ); @@ -486,7 +486,7 @@ float x = stack.Arg0().NumericByRefConst().r4; float y = stack.Arg1().NumericByRefConst().r4; - float res = System::Math::IEEERemainder(x, y); + float res = remainder(x, y); stack.SetResult_R4( res ); @@ -503,7 +503,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Exp( d ); + double res = exp( d ); stack.SetResult_R8( res ); @@ -524,7 +524,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Exp( d ); + float res = exp( d ); stack.SetResult_R4( res ); @@ -541,7 +541,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Floor( d ); + double res = floor( d ); stack.SetResult_R8( res ); @@ -562,7 +562,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Floor( d ); + float res = floor( d ); stack.SetResult_R4( res ); @@ -579,7 +579,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Log( d ); + double res = log( d ); stack.SetResult_R8( res ); @@ -600,7 +600,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Log( d ); + float res = log( d ); stack.SetResult_R4( res ); @@ -617,7 +617,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Log10( d ); + double res = log10( d ); stack.SetResult_R8( res ); @@ -638,7 +638,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Log10( d ); + float res = log10( d ); stack.SetResult_R4( res ); @@ -656,7 +656,7 @@ double x = stack.Arg0().NumericByRefConst().r8; double y = stack.Arg1().NumericByRefConst().r8; - double res = System::Math::Pow( x, y ); + double res = pow( x, y ); stack.SetResult_R8( res ); @@ -678,7 +678,7 @@ float x = stack.Arg0().NumericByRefConst().r4; float y = stack.Arg1().NumericByRefConst().r4; - float res = System::Math::Pow( x, y ); + float res = pow( x, y ); stack.SetResult_R4( res ); @@ -695,18 +695,8 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double hi = d + 0.5; - double res = System::Math::Floor( hi ); - - //If the number was in the middle of two integers, we need to round to the even one. - if(res==hi) - { - if(System::Math::Fmod( res, 2.0 ) != 0) - { - //Rounding up made the number odd so we should round down. - res -= 1.0; - } - } + + double res = round(d); stack.SetResult_R8( res ); @@ -727,18 +717,8 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float hi = d + 0.5; - float res = System::Math::Floor( hi ); - - //If the number was in the middle of two integers, we need to round to the even one. - if(res==hi) - { - if(System::Math::Fmod( res, 2.0 ) != 0) - { - //Rounding up made the number odd so we should round down. - res -= 1.0; - } - } + + float res = roundf(d); stack.SetResult_R4( res ); @@ -797,7 +777,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Sin( d ); + double res = sin( d ); stack.SetResult_R8( res ); @@ -818,7 +798,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Sin( d ); + float res = sin( d ); stack.SetResult_R4( res ); @@ -835,7 +815,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Sinh( d ); + double res = sinh( d ); stack.SetResult_R8( res ); @@ -856,7 +836,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Sinh( d ); + float res = sinh( d ); stack.SetResult_R4( res ); @@ -873,7 +853,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Sqrt( d ); + double res = sqrt( d ); stack.SetResult_R8( res ); @@ -894,7 +874,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Sqrt( d ); + float res = sqrt( d ); stack.SetResult_R4( res ); @@ -911,7 +891,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Tan( d ); + double res = tan( d ); stack.SetResult_R8( res ); @@ -932,7 +912,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Tan( d ); + float res = tan( d ); stack.SetResult_R4( res ); @@ -949,7 +929,7 @@ NANOCLR_HEADER(); double d = stack.Arg0().NumericByRefConst().r8; - double res = System::Math::Tanh( d ); + double res = tanh( d ); stack.SetResult_R8( res ); @@ -970,7 +950,7 @@ NANOCLR_HEADER(); float d = stack.Arg0().NumericByRefConst().r4; - float res = System::Math::Tanh( d ); + float res = tanh( d ); stack.SetResult_R4( res ); @@ -1009,7 +989,7 @@ float d = stack.Arg0().NumericByRefConst().r4; float res = 0.0; - float retVal = System::Math::Truncate(d, res); + float retVal = modf(d, (double*)&res); stack.SetResult_R4( retVal ); diff --git a/src/PAL/Double/nanoPAL_NativeDouble.cpp b/src/PAL/Double/nanoPAL_NativeDouble.cpp index 1abf6e178c..6df893cec4 100644 --- a/src/PAL/Double/nanoPAL_NativeDouble.cpp +++ b/src/PAL/Double/nanoPAL_NativeDouble.cpp @@ -194,314 +194,3 @@ bool Double::IsPositiveInfinity( double d ) bool retVal = (signBit == 0) && (infiniteBit != 0); return retVal; } - -#if (DP_FLOATINGPOINT == TRUE) - // double-precision floating point - - double Math::Abs( double d ) - { - double retVal = fabs(d); - return retVal; - } - - double Math::Acos( double d ) - { - double retVal = acos(d); - return retVal; - } - - double Math::Asin( double d ) - { - double retVal = asin(d); - return retVal; - } - - double Math::Atan( double d ) - { - double retVal = atan(d); - return retVal; - } - - double Math::Atan2( double x, double y ) - { - double retVal = atan2(x,y); - return retVal; - } - - double Math::Ceiling( double d ) - { - double retVal = ceil(d); - return retVal; - } - - double Math::Cos( double d ) - { - double retVal = cos(d); - return retVal; - } - - double Math::Cosh( double d ) - { - double retVal = cosh(d); - return retVal; - } - - double Math::IEEERemainder( double x, double y ) - { - double retVal = remainder(x, y); - return retVal; - } - - double Math::Exp( double d ) - { - double retVal = exp(d); - return retVal; - } - - double Math::Floor( double d ) - { - double retVal = floor(d); - return retVal; - } - - double Math::Fmod( double x, double y ) - { - double retVal = fmod(x, y); - return retVal; - } - - - double Math::Log( double d ) - { - double retVal = log(d); - return retVal; - } - - double Math::Log10( double d ) - { - double retVal = log10(d); - return retVal; - } - - double Math::Max( double x, double y) - { - return x >= y ? x : y; - } - - double Math::Min( double x, double y) - { - return x <= y ? x : y; - } - - double Math::Pow( double x, double y) - { - double retVal = pow(x, y); - return retVal; - } - - double Math::Round( double d ) - { - double retVal = rint(d); - return retVal; - } - - int32_t Math::Sign( double d ) - { - if (d < 0) return -1; - if (d > 0) return +1; - return 0; - } - - double Math::Sin( double d ) - { - double retVal = sin(d); - return retVal; - } - - double Math::Sinh( double d ) - { - double retVal = sinh(d); - return retVal; - } - - double Math::Sqrt( double d ) - { - double retVal = sqrt(d); - return retVal; - } - - double Math::Tan( double d ) - { - double retVal = tan(d); - return retVal; - } - - double Math::Tanh( double d ) - { - double retVal = tanh(d); - return retVal; - } - - double Math::Truncate( double d, double& integralValue ) - { - integralValue = 0; - double retVal = modf(d, &integralValue); - return retVal; - } - -#else - - // single-precision floating point - - float Math::Abs( float d ) - { - float retVal = fabs(d); - return retVal; - } - - float Math::Acos( float d ) - { - float retVal = acos(d); - return retVal; - } - - float Math::Asin( float d ) - { - float retVal = asin(d); - return retVal; - } - - float Math::Atan( float d ) - { - float retVal = atan(d); - return retVal; - } - - float Math::Atan2( float x, float y ) - { - float retVal = atan2(x,y); - return retVal; - } - - float Math::Ceiling( float d ) - { - float retVal = ceil(d); - return retVal; - } - - float Math::Cos( float d ) - { - float retVal = cos(d); - return retVal; - } - - float Math::Cosh( float d ) - { - float retVal = cosh(d); - return retVal; - } - - float Math::IEEERemainder( float x, float y ) - { - float retVal = remainder(x, y); - return retVal; - } - - float Math::Exp( float d ) - { - float retVal = exp(d); - return retVal; - } - - float Math::Floor( float d ) - { - float retVal = floor(d); - return retVal; - } - - float Math::Fmod( float x, float y ) - { - float retVal = fmod(x, y); - return retVal; - } - - - float Math::Log( float d ) - { - float retVal = log(d); - return retVal; - } - - float Math::Log10( float d ) - { - float retVal = log10(d); - return retVal; - } - - float Math::Max( float x, float y) - { - return x >= y ? x : y; - } - - float Math::Min( float x, float y) - { - return x <= y ? x : y; - } - - float Math::Pow( float x, float y) - { - float retVal = pow(x, y); - return retVal; - } - - float Math::Round( float d ) - { - float retVal = rint(d); - return retVal; - } - - int32_t Math::Sign( float d ) - { - if (d < 0) return -1; - if (d > 0) return +1; - return 0; - } - - float Math::Sin( float d ) - { - float retVal = sin(d); - return retVal; - } - - float Math::Sinh( float d ) - { - float retVal = sinh(d); - return retVal; - } - - float Math::Sqrt( float d ) - { - float retVal = sqrt(d); - return retVal; - } - - float Math::Tan( float d ) - { - float retVal = tan(d); - return retVal; - } - - float Math::Tanh( float d ) - { - float retVal = tanh(d); - return retVal; - } - - float Math::Truncate( float d, float& integralValue ) - { - integralValue = 0; - float retVal = modf(d, (double*)&integralValue); - return retVal; - } - -#endif // DP_FLOATINGPOINT diff --git a/src/PAL/Include/nanoPAL_NativeDouble.h b/src/PAL/Include/nanoPAL_NativeDouble.h index 23f8caeea8..ebb21b2c18 100644 --- a/src/PAL/Include/nanoPAL_NativeDouble.h +++ b/src/PAL/Include/nanoPAL_NativeDouble.h @@ -18,68 +18,6 @@ namespace System static bool IsNegativeInfinity( double d ); static bool IsPositiveInfinity( double d ); }; - - struct Math - { - #if (DP_FLOATINGPOINT == TRUE) - // double-precision floating point - - static double Abs(double d); - static double Acos(double d); - static double Asin(double d); - static double Atan(double d); - static double Atan2(double x, double y); - static double Ceiling(double d); - static double Cos(double d); - static double Cosh(double d); - static double IEEERemainder(double x, double y ); - static double Exp(double d); - static double Floor(double d); - static double Fmod(double x, double y ); - static double Log(double d); - static double Log10(double d); - static double Max(double x, double y); - static double Min(double x, double y); - static double Pow(double x, double y); - static double Round(double d); - static int32_t Sign(double d); - static double Sin(double d); - static double Sinh(double d); - static double Sqrt(double d); - static double Tan(double d); - static double Tanh(double d); - static double Truncate(double d, double& integralValue); - - #else - // single-precision floating point - - static float Abs(float d); - static float Acos(float d); - static float Asin(float d); - static float Atan(float d); - static float Atan2(float x, float y); - static float Ceiling(float d); - static float Cos(float d); - static float Cosh(float d); - static float IEEERemainder(float x, float y ); - static float Exp(float d); - static float Floor(float d); - static float Fmod(float x, float y ); - static float Log(float d); - static float Log10(float d); - static float Max(float x, float y); - static float Min(float x, float y); - static float Pow(float x, float y); - static float Round(float d); - static int32_t Sign(float d); - static float Sin(float d); - static float Sinh(float d); - static float Sqrt(float d); - static float Tan(float d); - static float Tanh(float d); - static float Truncate(float d, float& integralValue); - - #endif // DP_FLOATINGPOINT - }; } + #endif //_NANOPAL_DOUBLE_DECL_H_