# Difference between the operator % of Motoko and Smalltalk

**URL:** <https://forum.dfinity.org/t/difference-between-the-operator-of-motoko-and-smalltalk/38822>\
**Category:** Motoko\
**Created:** [December 13, 2024, 1:04pm UTC](https://forum.dfinity.org/t/difference-between-the-operator-of-motoko-and-smalltalk/38822 "2024-12-13T13:04:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chicoary](https://avatars.discourse-cdn.com/v4/letter/c/db5fbb/32.png) [@chicoary](https://forum.dfinity.org/u/chicoary)\
**Post date:** [December 13, 2024, 1:04pm UTC](https://forum.dfinity.org/t/difference-between-the-operator-of-motoko-and-smalltalk/38822/1 "2024-12-13T13:04:47Z")

</div>

I’m porting Smalltalk to Motoko and I’ve found a semantic difference between Motoko’s `%` operator and the same `%` operator in Smalltalk. For Motoko’s `%` operator to return the same result as Smalltalk’s it should, for integers, return `a % b = a - (if (a/b > 0) a / b else a/b - 1) * b` and for `Floats` `a % b = a - Float.floor(a/b)*b`. It seems to me that the definition in Smalltalk is more consistent and coherent than Motoko’s.

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [December 13, 2024, 2:50pm UTC](https://forum.dfinity.org/t/difference-between-the-operator-of-motoko-and-smalltalk/38822/2 "2024-12-13T14:50:39Z")

</div>

Thanks for reporting this.

I’m actually not sure what the correct answer should be but I’ve opened an issue below.  
We probably just expose the Wasm semantics, but would need to check.

> <https://github.com/dfinity/motoko/issues/4823>
>
> \_I’m porting Smalltalk to Motoko and I’ve found a semantic difference between Mo…toko’s % operator and the same % operator in Smalltalk. For Motoko’s % operator to return the same result as Smalltalk’s it should, for integers, return a % b = a - (if (a/b \> 0) a / b else a/b - 1) \* b and for Floats a % b = a - Float.floor(a/b)\*b. It seems to me that the definition in Smalltalk is more consistent and coherent than Motoko’s.\_
> 
> https://forum.dfinity.org/t/difference-between-the-operator-of-motoko-and-smalltalk/38822/1

---

<div class="post-metadata">

**Author:** ![ggreif](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ggreif/32/301_2.png) [@ggreif](https://forum.dfinity.org/u/ggreif)\
**Post date:** [December 13, 2024, 3:34pm UTC](https://forum.dfinity.org/t/difference-between-the-operator-of-motoko-and-smalltalk/38822/3 "2024-12-13T15:34:51Z")

</div>

`%` is supposed to make sense in _rings_, but `Float` is assumed to be a _field_ so every division is without remainder. So I am a bit surprised we have that for `Float`s at all 🙂

---

<div class="post-metadata">

**Author:** ![chicoary](https://avatars.discourse-cdn.com/v4/letter/c/db5fbb/32.png) [@chicoary](https://forum.dfinity.org/u/chicoary)\
**Post date:** [December 13, 2024, 11:26pm UTC](https://forum.dfinity.org/t/difference-between-the-operator-of-motoko-and-smalltalk/38822/4 "2024-12-13T23:26:39Z")

</div>

In both Smalltalk and Motoko you can write: `9.2 % 3.9` and, in this case, the result is the same: `1.3999999999999995`. Smalltalk starts to differ from Motoko when one of the arguments is negative.
