简体   繁体   English

如何在 C# 中计算 fmod?

[英]How to compute fmod in C#?

For given floating point numbers x and a , I would like to compute r (and n ) such that x = a*n + r .对于给定的浮点数xa ,我想计算r (和n )使得x = a*n + r In C/C++ this function is called fmod .在 C/C++ 中,此函数称为fmod However I do not see a convenient function in .NET.但是我在 .NET 中没有看到方便的功能。 Math.DivRem is only for integers ... Math.DivRem 仅适用于整数......

I think you can just use % for floats as well.我认为您也可以将%用于浮点数。 r = x % a

" Arithmetic operators (C# reference) ": 算术运算符(C# 参考) ”:

All numeric types have predefined modulus operators.所有数字类型都有预定义的模运算符。

我想你正在寻找System.Math.IeeeRemainder

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

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