/// <summary cref="XMath.IEEERemainder(float, float)"/> public static float IEEERemainder(float x, float y) { if (y == 0.0f || XMath.IsInfinity(x) || XMath.IsNaN(x) || XMath.IsNaN(y)) { return(float.NaN); } if (XMath.IsInfinity(y)) { return(x); } return(x - (y * XMath.RoundToEven(x * XMath.Rcp(y)))); }
public static double IEEERemainder(double x, double y) { if (y == 0.0 || XMath.IsInfinity(x) || XMath.IsNaN(x) || XMath.IsNaN(y)) { return(double.NaN); } if (XMath.IsInfinity(y)) { return(x); } return(x - (y * XMath.RoundToEven(x * XMath.Rcp(y)))); }
public static float Log(float value, float newBase) { if (value < 0.0f || newBase < 0.0f || (value != 1.0f && newBase == 0.0f) || (value != 1.0f && newBase == float.PositiveInfinity) || XMath.IsNaN(value) || XMath.IsNaN(newBase) || newBase == 1.0f) { return(float.NaN); } if (value == 0.0f) { if (0.0f < newBase && newBase < 1.0f) { return(float.PositiveInfinity); } else if (newBase > 1.0f) { return(float.NegativeInfinity); } } if (value == float.PositiveInfinity) { if (0.0f < newBase && newBase < 1.0f) { return(float.NegativeInfinity); } else if (newBase > 1.0f) { return(float.PositiveInfinity); } } if (value == 1.0f && (newBase == 0.0f || newBase == float.PositiveInfinity)) { return(0.0f); } return(XMath.Log(value) * XMath.Rcp(XMath.Log(newBase))); }
public static double Log(double value, double newBase) { if (value < 0.0 || newBase < 0.0 || (value != 1.0 && newBase == 0.0) || (value != 1.0 && newBase == double.PositiveInfinity) || XMath.IsNaN(value) || XMath.IsNaN(newBase) || newBase == 1.0) { return(double.NaN); } if (value == 0.0) { if (0.0 < newBase && newBase < 1.0) { return(double.PositiveInfinity); } else if (newBase > 1.0) { return(double.NegativeInfinity); } } if (value == double.PositiveInfinity) { if (0.0 < newBase && newBase < 1.0) { return(double.NegativeInfinity); } else if (newBase > 1.0) { return(double.PositiveInfinity); } } if (value == 1.0 && (newBase == 0.0 || newBase == double.PositiveInfinity)) { return(0.0); } return(XMath.Log(value) * XMath.Rcp(XMath.Log(newBase))); }
public static double Rem(double x, double y) { if (y == 0.0 || XMath.IsInfinity(x) || XMath.IsNaN(x) || XMath.IsNaN(y)) { return(double.NaN); } if (XMath.IsInfinity(y)) { return(x); } var xDivY = XMath.Abs(x * XMath.Rcp(y)); var result = (xDivY - Floor(xDivY)) * XMath.Abs(y); return(Utilities.Select(x < 0.0, -result, result)); }
public static float Tanh(float value) { if (XMath.IsNaN(value)) { return(value); } else if (value == float.PositiveInfinity) { return(1.0f); } else if (value == float.NegativeInfinity) { return(-1.0f); } var exp = Exp(2.0f * value); var denominator = XMath.Rcp(exp + 1.0f); return((exp - 1.0f) * denominator); }
public static double Tanh(double value) { if (XMath.IsNaN(value)) { return(value); } else if (value == double.PositiveInfinity) { return(1.0); } else if (value == double.NegativeInfinity) { return(-1.0); } var exp = Exp(2.0 * value); var denominator = XMath.Rcp(exp + 1.0); return((exp - 1.0) * denominator); }
public static float Rem(float x, float y) { if (y == 0.0f || XMath.IsInfinity(x) || XMath.IsNaN(x) || XMath.IsNaN(y)) { return(float.NaN); } if (XMath.IsInfinity(y)) { return(x); } var xDivY = XMath.Abs(x * XMath.Rcp(y)); var result = (xDivY - Floor(xDivY)) * XMath.Abs(y); return(Utilities.Select(x < 0.0f, -result, result)); }
public static float Asin(float value) { if (XMath.IsNaN(value) || value < -1.0f || value > 1.0f) { return(float.NaN); } if (value == 1.0f) { return(XMath.PIHalf); } else if (value == -1.0f) { return(-XMath.PIHalf); } float arg = value * Rsqrt(1.0f - value * value); return(Atan(arg)); }
public static double Asin(double value) { if (XMath.IsNaN(value) || value < -1.0 || value > 1.0) { return(double.NaN); } if (value == 1.0) { return(XMath.PIHalfD); } else if (value == -1.0) { return(-XMath.PIHalfD); } double arg = value * Rsqrt(1.0 - value * value); return(Atan(arg)); }
public static float Pow(float @base, float exp) { if (exp == 0.0f) { // Rule #2 // Ignoring Rule #1 return(1.0f); } else if (@base == 1.0f) { // Rule #14 but ignoring second part about y = NaN // Ignoring Rule #1 return(1.0f); } else if (XMath.IsNaN(@base) || XMath.IsNaN(exp)) { // Rule #1 return(float.NaN); } else if (@base == float.NegativeInfinity) { if (exp < 0.0f) { // Rule #3 return(0.0f); } else if (IsOddInteger(exp)) { // Rule #4 return(float.NegativeInfinity); } else { // Rule #5 return(float.PositiveInfinity); } } else if (@base < 0.0f && !IsInteger(exp) && !XMath.IsInfinity(exp)) { // Rule #6 return(float.NaN); } else if (@base == -1.0f && XMath.IsInfinity(exp)) { // Rule #7 return(1.0f); } else if (-1.0f < @base && @base < 1.0f && exp == float.NegativeInfinity) { // Rule #8 return(float.PositiveInfinity); } else if (-1.0f < @base && @base < 1.0f && exp == float.PositiveInfinity) { // Rule #9 return(0.0f); } else if ((@base < -1.0f || @base > 1.0f) && exp == float.NegativeInfinity) { // Rule #10 return(0.0f); } else if ((@base < -1.0f || @base > 1.0f) && exp == float.PositiveInfinity) { // Rule #11 return(float.PositiveInfinity); } else if (@base == 0.0f) { if (exp < 0.0f) { // Rule #12 return(float.PositiveInfinity); } else { // Rule #13 // NB: exp == 0.0 already handled by Rule #2 return(0.0f); } } else if (@base == float.PositiveInfinity) { if (exp < 0.0f) { // Rule #15 return(0.0f); } else { // Rule #16 // NB: exp == 0.0 already handled by Rule #2 return(float.PositiveInfinity); } } if (@base < 0.0) { // 'exp' is an integer, due to Rule #6. var sign = IsOddInteger(exp) ? -1.0f : 1.0f; return(sign * Exp(exp * Log(XMath.Abs(@base)))); } return(Exp(exp * Log(@base))); }
public static float Pow(float @base, float exp) { // TODO: The second condition of !XMath.IsNaN(), for the first two if/else conditions, // can be removed after fixing https://github.com/m4rs-mt/ILGPU/issues/93 if (exp == 0.0f && !XMath.IsNaN(exp)) { // Rule #2 // Ignoring Rule #1 return(1.0f); } else if (@base == 1.0f && !XMath.IsNaN(@base)) { // Rule #14 but ignoring second part about y = NaN // Ignoring Rule #1 return(1.0f); } else if (XMath.IsNaN(@base) || XMath.IsNaN(exp)) { // Rule #1 return(float.NaN); } else if (@base == float.NegativeInfinity) { if (exp < 0.0f) { // Rule #3 return(0.0f); } else if (IsOddInteger(exp)) { // Rule #4 return(float.NegativeInfinity); } else { // Rule #5 return(float.PositiveInfinity); } } else if (@base < 0.0f && !IsInteger(exp) && !XMath.IsInfinity(exp)) { // Rule #6 return(float.NaN); } else if (@base == -1.0f && XMath.IsInfinity(exp)) { // Rule #7 return(1.0f); } else if (-1.0f < @base && @base < 1.0f && exp == float.NegativeInfinity) { // Rule #8 return(float.PositiveInfinity); } else if (-1.0f < @base && @base < 1.0f && exp == float.PositiveInfinity) { // Rule #9 return(0.0f); } else if ((@base < -1.0f || @base > 1.0f) && exp == float.NegativeInfinity) { // Rule #10 return(0.0f); } else if ((@base < -1.0f || @base > 1.0f) && exp == float.PositiveInfinity) { // Rule #11 return(float.PositiveInfinity); } else if (@base == 0.0f) { if (exp < 0.0f) { // Rule #12 return(float.PositiveInfinity); } else { // Rule #13 // NB: exp == 0.0 already handled by Rule #2 return(0.0f); } } else if (@base == float.PositiveInfinity) { if (exp < 0.0f) { // Rule #14 return(0.0f); } else { // Rule #15 // NB: exp == 0.0 already handled by Rule #2 return(float.PositiveInfinity); } } if (@base < 0.0) { // 'exp' is an integer, due to Rule #6. var sign = IsOddInteger(exp) ? -1.0f : 1.0f; return(sign * Exp(exp * Log(XMath.Abs(@base)))); } return(Exp(exp * Log(@base))); }