我正在尝试找出浮点数据类型的简单模数运算.
float a=3.14f;浮动 b=10f;结果=a%b;我得到的结果= 3.14
另一个使用十进制数据类型的例子:
十进制 p=10;十进制 q=40;结果=p%q;得到答案=20.
我不明白模数是如何工作的?
来自关于浮点余数的 C# 语言规范.在 x % y 的情况下,如果 x 和 y 是正有限值.
z 是 x % y 的结果,计算为 x – n * y,其中 n是小于或等于 x/y 的最大可能整数.
C# 语言规范还清楚地概述了如何处理浮点值 x % y 可能出现的非零有限值、零、无穷大和 NaN 的所有可能组合的情况.
<块引用> y 值|+y –y +0 –0 +∞ –∞ NaN-----+----------------x +x |+z +z NaN NaN x x NaN-x |–z –z NaN NaN –x –x NaNv +0 |+0 +0 NaN NaN +0 +0 NaN一个 –0 |–0 –0 NaN NaN –0 –0 NaNl +∞ |南 南 南 南 南 南 南 南u –∞ |南 南 南 南 南 南 南 南e NaN |南 南 南 南 南 南 南 南I m trying to find out a simple modulus operation on float data type.
float a=3.14f;
float b=10f;
result=a%b;
I m getting result= 3.14
Another example using decimal data types:
decimal p=10;
decimal q=40;
result=p%q;
getting answer=20.
I am not understanding how does modulus works?
From the C# language spec on floating point remainder. In the case of x % y if x and y are positive finite values.
zis the result ofx % yand is computed asx – n * y, wherenis the largest possible integer that is less than or equal tox / y.
The C# language spec also clearly outlines the table of what to do with the cases of all possible combinations of nonzero finite values, zeros, infinities, and NaN’s which can occur with floating point values of x % y.
y value | +y –y +0 –0 +∞ –∞ NaN -----+---------------------------- x +x | +z +z NaN NaN x x NaN –x | –z –z NaN NaN –x –x NaN v +0 | +0 +0 NaN NaN +0 +0 NaN a –0 | –0 –0 NaN NaN –0 –0 NaN l +∞ | NaN NaN NaN NaN NaN NaN NaN u –∞ | NaN NaN NaN NaN NaN NaN NaN e NaN | NaN NaN NaN NaN NaN NaN NaN
这篇关于模数运算如何与浮点数据类型一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
ASP.NET Core 使用 Azure Active Directory 进行身份验证并ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 进行身
ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用)
ASP Core Azure Active Directory 登录使用角色ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登录使用角色)
如何获取守护进程或服务器到 C# ASP.NET Web API 的How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何获取守护进程或服务器到 C# ASP.N
.Net Core 2.0 - 获取 AAD 访问令牌以与 Microsoft Graph.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 获取 AAD 访问令牌以与 Microsoft Graph 一起使用)
异步调用时 Azure KeyVault Active Directory AcquireTokenAAzure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(异步调用时 Azure KeyVault Active Directory AcquireTokenAsync 超