简体   繁体   English

等效于C#中的PHP fmod

[英]Equivalent of the php fmod in C#

Does anybody know what the C# equivalent of fmod is? 有人知道fmod的C#等效项是什么吗? I'm trying to convert this line of code to C#. 我正在尝试将这行代码转换为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. 我只需要转换fmod。

double lon_rad = ((lon1+dlon_rad + Math.PI), 2*Math.PI) - Math.PI;

其他人给了正确的运算符,但没有给出完整的语法,这是:

double lon_rad = ((lon1+dlon_rad + Math.PI) % (2*Math.PI)) - Math.PI;

Use a P/Invoked call into the standard library (from here ): 使用P / Invoked调用进入标准库(从此处开始 ):

[DllImport("msvcrt.dll")]
static extern double fmod(double x, double y);

您是否尝试过%模数运算符?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM