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

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

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

問題描述

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

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

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

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)

推薦答案

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

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

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

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.)

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

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

相關文檔推薦

Algorithm to convert RGB to HSV and HSV to RGB in range 0-255 for both(將 RGB 轉換為 HSV 并將 HSV 轉換為 RGB 的算法,范圍為 0-255)
How to convert an enum type variable to a string?(如何將枚舉類型變量轉換為字符串?)
When to use inline function and when not to use it?(什么時候使用內聯函數,什么時候不使用?)
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 仍然相關嗎?)
主站蜘蛛池模板: 91精品国产一区二区三区蜜臀 | 九九视频在线观看 | 涩涩操| 天天干天天爽 | 国产91久久精品一区二区 | 91精品国产综合久久婷婷香蕉 | 亚洲第一免费播放区 | 色综合色综合色综合 | 亚洲国产成人精品女人久久久 | 久久99蜜桃综合影院免费观看 | 国产一区二区观看 | 欧美成年网站 | 欧美日韩一区二区三区四区 | 一级免费黄色 | 中文字幕视频一区二区 | 国内精品视频免费观看 | 日韩在线观看中文字幕 | 日韩欧美国产精品 | av av在线| 在线观看av网站 | 亚洲免费在线 | 久久精品免费一区二区 | 91精品国产91 | 日韩一区二区在线视频 | 国产亚洲精品综合一区 | 久久久久国产精品一区三寸 | 国产成人精品综合 | 国产精品久久久久无码av | 国产一区二区三区在线看 | 久久久噜噜噜久久中文字幕色伊伊 | 国产激情一区二区三区 | 国产一级在线观看 | 日韩在线日韩 | 黑人巨大精品欧美一区二区免费 | 久久777| 欧美久久久电影 | 成年男女免费视频网站 | 欧美一级片久久 | 午夜电影网 | 91视频一88av | 日韩久久久久 |