开发者

Equivalent of the php fmod in C#

开发者 https://www.devze.com 2022-12-12 06:04 出处:网络
Does anybody know what the C# equivalent of fmod is?I\'m trying to convert this li开发者_如何学Gone of code to C#.

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消