简体   繁体   中英

Modulo function in Clean

Is there a predefined way to compute the modulo of two integers in Clean?

StdOverloaded defines the (mod) typeclass, but StdInt does not contain an instance of it, and StdEnv does not either anywhere else. 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.

StdInt delivers another alternative: it's called rem. Works just like the old fashioned mod function, but also works fine with signed integers.

10 rem 7 // 3

10 rem -7 // 3

-10 rem 7 // -3

-10 rem -7 //-3

在最新的稳定版本 (Clean 3.0) 中,只需导入 StdEnv 实例就可以使用“rem”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM