Does anybody know what the C# equivalent of fmod is? I'm trying to convert this li开发者_如何学Gone of code to C#.
$lon_rad = fmod(($long1+$dlon_rad + M_PI), 2*M_PI) - M_PI;
Here's what I have so far. I just need the fmod converted.
double lon_rad = ((lon1+dlon_rad + Math.PI), 2*Math.PI) - Math.PI;
Other people have given the correct operator to use, but not the entire syntax, which would be:
double lon_rad = ((lon1+dlon_rad + Math.PI) % (2*Math.PI)) - Math.PI;
Use a P/Invoked call into the standard library (from here):
[DllImport("msvcrt.dll")]
static extern double fmod(double x, double y);
Have you tried the % modulus operator?
public static double fmod(double dividend, double divisor )
{
double Modulus =
(Math.Abs(dividend) - (Math.Abs(divisor) *
(Math.Floor(Math.Abs(dividend) / Math.Abs(divisor))))) *
Math.Sign(dividend);
return Modulus;
}
精彩评论