[英]Modulo function in Clean
Is there a predefined way to compute the modulo of two integers in Clean?是否有预定义的方法来计算 Clean 中两个整数的模数?
StdOverloaded defines the (mod) typeclass, but StdInt does not contain an instance of it, and StdEnv does not either anywhere else. StdOverloaded 定义了 (mod) 类型类,但 StdInt 不包含它的实例,StdEnv 也不包含其他任何地方。 I have seen a language overview about Clean version 2.0, which mentions StdInt's mod instance, but in 2.4, it is definitely missing.
我看过关于 Clean 2.0 版的语言概述,其中提到了 StdInt 的 mod 实例,但在 2.4 中,它肯定是缺失的。
StdInt delivers another alternative: it's called rem. StdInt 提供了另一种选择:它称为 rem。 Works just like the old fashioned mod function, but also works fine with signed integers.
就像老式的 mod 函数一样工作,但也适用于有符号整数。
10 rem 7 // 3
10 rem -7 // 3
-10 rem 7 // -3
-10 rem -7 //-3
在最新的稳定版本 (Clean 3.0) 中,只需导入 StdEnv 实例就可以使用“rem”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.