久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么模數(shù)除法 (%) 僅適用于整數(shù)?

Why does modulus division (%) only work with integers?(為什么模數(shù)除法 (%) 僅適用于整數(shù)?)
本文介紹了為什么模數(shù)除法 (%) 僅適用于整數(shù)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我最近遇到了一個問題 可以使用模數(shù)除法輕松解決,但輸入是浮點數(shù):

I recently ran into an issue that could easily be solved using modulus division, but the input was a float:

給定一個周期函數(shù)(例如sin)和一個只能在周期范圍內(nèi)計算它的計算機函數(shù)(例如[-π, π]),制作一個可以處理任何輸入的函數(shù).

Given a periodic function (e.g. sin) and a computer function that can only compute it within the period range (e.g. [-π, π]), make a function that can handle any input.

明顯"的解決方案類似于:

The "obvious" solution is something like:

#include <cmath>

float sin(float x){
    return limited_sin((x + M_PI) % (2 *M_PI) - M_PI);
}

為什么這不起作用?我收到此錯誤:

Why doesn't this work? I get this error:

error: invalid operands of types double and double to binary operator %

有趣的是,它確實適用于 Python:

Interestingly, it does work in Python:

def sin(x):
    return limited_sin((x + math.pi) % (2 * math.pi) - math.pi)

推薦答案

因為余數(shù)"的正常數(shù)學(xué)概念僅適用于整數(shù)除法.即生成整數(shù)商所需的除法.

Because the normal mathematical notion of "remainder" is only applicable to integer division. i.e. division that is required to generate integer quotient.

為了將余數(shù)"的概念擴展到實數(shù),您必須引入一種新的混合"操作,該操作將為實數(shù)操作數(shù)生成整數(shù)商.核心 C 語言不支持這種操作,但它作為標(biāo)準(zhǔn)庫提供 fmod 函數(shù),以及 remainder 函數(shù)C99.(注意,這些函數(shù)并不相同,有一些特殊性.特別是,它們不遵循整數(shù)除法的舍入規(guī)則.)

In order to extend the concept of "remainder" to real numbers you have to introduce a new kind of "hybrid" operation that would generate integer quotient for real operands. Core C language does not support such operation, but it is provided as a standard library fmod function, as well as remainder function in C99. (Note that these functions are not the same and have some peculiarities. In particular, they do not follow the rounding rules of integer division.)

這篇關(guān)于為什么模數(shù)除法 (%) 僅適用于整數(shù)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Algorithm to convert RGB to HSV and HSV to RGB in range 0-255 for both(將 RGB 轉(zhuǎn)換為 HSV 并將 HSV 轉(zhuǎn)換為 RGB 的算法,范圍為 0-255)
How to convert an enum type variable to a string?(如何將枚舉類型變量轉(zhuǎn)換為字符串?)
When to use inline function and when not to use it?(什么時候使用內(nèi)聯(lián)函數(shù),什么時候不使用?)
Examples of good gotos in C or C++(C 或 C++ 中好的 goto 示例)
Significance of ios_base::sync_with_stdio(false); cin.tie(NULL);(ios_base::sync_with_stdio(false) 的意義;cin.tie(NULL);)
Is TCHAR still relevant?(TCHAR 仍然相關(guān)嗎?)
主站蜘蛛池模板: 中文字幕伊人 | 99热99re6国产在线播放 | 亚洲天堂中文字幕 | 日韩av成人在线 | 国产人成 | 黄色小说在线免费观看 | 日韩精品免费看 | 97视频在线观看免费 | 日韩中文字幕一区二区三区 | 麻豆亚洲一区 | 国产三级在线观看视频 | 国产精品国产成人国产三级 | 久久精品观看 | 九九久久久 | 中文字幕在线日韩 | 97人人爱 | 成人在线观看免费爱爱 | 亚洲综合日韩 | 精品少妇一区二区三区免费观 | 91看片淫黄大片 | 在线免费观看黄 | 国产一级免费观看 | 黄色网址免费看 | 欧美性生交xxxxx久久久 | 婷婷俺也去| 精品毛片一区二区三区 | 一区二区三区在线免费 | 日本一级一片免费视频 | 亚洲在线观看视频 | 国产精品成人一区 | 色影视| 免费av网址在线观看 | 日韩一区不卡 | 色婷婷在线视频 | 一区二区免费看 | 黄色aaa| 久久日av| 国产三级视频在线播放 | 国产欧美一区二区 | 亚洲视频在线观看一区 | 中文字幕理伦片免费看 |