# Remainder(modulus) operator returning negative values when it shouldn't

**URL:** https://forum.makecode.com/t/remainder-modulus-operator-returning-negative-values-when-it-shouldnt/1789
**Category:** Help
**Created:** [April 23, 2020, 2:24pm UTC](https://forum.makecode.com/t/remainder-modulus-operator-returning-negative-values-when-it-shouldnt/1789 "2020-04-23T14:24:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Nova](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@Nova](https://forum.makecode.com/u/Nova)
#### Post date: [April 23, 2020, 2:24pm UTC](https://forum.makecode.com/t/remainder-modulus-operator-returning-negative-values-when-it-shouldnt/1789/1 "2020-04-23T14:24:03Z")

</div>

I was having problems when using the remainder function until I realized that the function returns negative values when it shouldn’t

Example:  
-1 % 4  
this should equal to 3 but makecode interprets this as -1.

because of this values are constrained incorrectly and equations that would work in any actual computer language don’t work in makecode

is this bug known and how long until it can be fixed?

---

<div class="post-metadata">

### Author: ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)
#### Post date: [April 23, 2020, 2:59pm UTC](https://forum.makecode.com/t/remainder-modulus-operator-returning-negative-values-when-it-shouldnt/1789/2 "2020-04-23T14:59:44Z")

</div>

This is the correct behavior; JavaScript, along with the c like languages (c / c++ / java / etc) all share the same behavior with `%`, treating it as a remainder instead of a true modulus operator.

> <https://stackoverflow.com/questions/13683563/whats-the-difference-between-mod-and-remainder>

If I recall correctly, python does have `%` as modulus not remainder, which I’ll probably have to file a bug on as I’m assuming we don’t handle that in our python implementation (confirmed and filed [here](https://github.com/microsoft/pxt-microbit/issues/2886))
