英文:
What is the difference between '/' operator and "%/%" operator in r programming language?
问题
第三行和第四行代码有什么不同?
英文:
I came across below code
v <- c( 2,5.5,6)
t <- c(8, 3, 4)
print(v/t)
print(v%/%t)
In what way 3rd and 4th lines of code are different?
答案1
得分: 5
/
表示通常的除法。
关于 %/%
,文档 表示:
%%
表示x mod y
,%/%
表示整数除法。除非y == 0
,可以保证x == (x %% y) + y * (x %/% y)
(最多存在舍入误差)。
要查找此类运算符的文档,请在 R 控制台上输入以下内容:
help("%/%")
英文:
/
does the usual division.
Regarding %/%
, the documentation states:
> %%
indicates x mod y
and %/%
indicates integer division. It
is guaranteed that x == (x %% y) + y * ( x %/% y )
(up to
rounding error) unless y == 0
[…]
To find the documentation for such operators, enter the following on the R console:
help("%/%")
答案2
得分: 3
这两者都是算术运算符。第一个是除法,第二个是整数除法。请参考此链接:https://www.statmethods.net/management/operators.html
10/3
[1] 3.333333
10%/%3
[1] 3
另外,还有取模运算符 (x %% y)
10%%3
[1] 1
这就是我知道的关于除法运算符的全部信息
英文:
Both are arithmetic operators. The first one is division, the second is integer division. See here: https://www.statmethods.net/management/operators.html
> 10/3
[1] 3.333333
> 10%/%3
[1] 3
In addition, there is also modulus division (x %% y)
> 10%%3
[1] 1
That's all I know about division operators
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论