# Accumulate rotation with snapping

**URL:** https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609
**Category:** Coding Questions
**Created:** [November 18, 2019, 12:20pm UTC](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609 "2019-11-18T12:20:45Z")
**Posts on this page:** 11
**Page:** 2

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 27, 2019, 4:35pm UTC](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609/23 "2019-11-27T16:35:57Z")

</div>

Could you post the Code you use for the iCompiler so i can check it out, to see where the problem lies?

---

<div class="post-metadata">

### Author: ![ddownn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ddownn/32/2731_2.png) [@ddownn](https://discourse.processing.org/u/ddownn)
#### Post date: [November 27, 2019, 6:10pm UTC](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609/24 "2019-11-27T18:10:39Z")

</div>

It’s the one above posted yesterday

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 27, 2019, 6:26pm UTC](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609/25 "2019-11-27T18:26:13Z")

</div>

Got it, use :

```auto
 accMin = floor(accSec/60) < 0 ? ceil(accSec/60) : floor(accSec/60);

```

Instead of only setting it to floor(accSec/60).

That should solve it.

---

<div class="post-metadata">

### Author: ![ddownn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ddownn/32/2731_2.png) [@ddownn](https://discourse.processing.org/u/ddownn)
#### Post date: [November 28, 2019, 3:09am UTC](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609/26 "2019-11-28T03:09:23Z")

</div>

It does work, thanks. Do you know what it is that is keeping iCompiler from working the same way as the IDE with just floor(accSec/60)?

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 28, 2019, 11:27am UTC](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609/27 "2019-11-28T11:27:00Z")

</div>

The IDE works the way floor should work, unless you use Integer division. I can only assume how the internal difference is, but maybe something like this :

IDE with Integer Division: (pseudo Code) (there are no different methods, this one is just a representation of what results, not what happens)

```auto
void setup() {
   floor(-1/10);
}

float floor (float a) {
   return removeNumbersAfterPoint(a);
}

```

Prints :

```auto
1.9 = 1
1.1 = 1
1 = 1
0.9 = 0
0 = 0
-0.1 = 0
-0.9 = 0
-1 = -1
-1.1 = -1
-1.9 = 1

```

ICompiler with Integer Division: (pseudo)

```auto
float floor (float a) {
   return reduceNumberUntilBecomesInteger(a);
}

```

```auto
1.9 = 1
1.1 = 1
1 = 1
0.9 = 0
0.1 = 0
0 = 0
-0.1 = -1
-0.9 = -1
-1 = -1
-1.1 = -2
-1.9 = -2

```

The result are what you get if you Test it.

Edit : Both have the same (probably) way to calculate floor, but the iCompiler automatically converts Integer Division, so the actual Input for the method varies depending on which one you use.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [November 29, 2019, 9:10pm UTC](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609/28 "2019-11-29T21:10:33Z")

</div>

Floor is the lower / lesser / more negative integer – the “left” value on the number line –

So, floor(0.5) = 0 (left); floor(-0.5) = -1 (left)

```auto
 -1 ........... 0 ........... 1
  | <- -0.5 | <- 0.5 |

```

… although some languages instead truncate the fractional part, creating an inconsistency in how negative numbers are handled.

The thing that is suspicious to me is that you are using integer division, rather than dividing by 60.0. Is that intentional / necessary? As to why that would give different results in iCompiler, good guess from Lexyth, although it is hard to know if the project is closed source…

> <https://stackoverflow.com/questions/37308248/java-integer-division-doesnt-give-floor-for-negative-numbers/43638428#43638428>

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 29, 2019, 9:14pm UTC](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609/29 "2019-11-29T21:14:33Z")

</div>

We were talking about the IOS version and there isn‘t such a thing as Integer divison (or defined array sizes).

Also, you‘re right, flooring -0.1 and giving 0 is wrong mathematically.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [November 29, 2019, 9:26pm UTC](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609/30 "2019-11-29T21:26:32Z")

</div>

> [@Lexyth](#):
>
> the IOS version

Interesting – is iCompiler in ObjectiveC or Swift? I’m not sure if I have used that app.

I was assuming by “IDE” that you meant the PDE, is that right? If there isn’t such a thing as integer division in iCompiler then that could be exactly why there is a difference between PDE and iCompiler results – as there _is_ such a thing in Java…

---

<div class="post-metadata">

### Author: ![ddownn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ddownn/32/2731_2.png) [@ddownn](https://discourse.processing.org/u/ddownn)
#### Post date: [November 29, 2019, 9:45pm UTC](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609/31 "2019-11-29T21:45:46Z")

</div>

> [@jeremydouglass](#):
>
> using integer division, rather than dividing by 60.0. Is that intentional / necessary?

Not intentional. I don’t know about necessary, or appropriate. 😆  
I guess I’ll have to look at that some more, and see where my ignorance on that may be causing problems. I seem to remember 60 vs. 60.0 giving me trouble before, but I didn’t really digest the problem.  
Is there anything obviously wrong here that you have noticed?

> [@jeremydouglass](#):
>
> by “IDE” that you meant the PDE

Yes, the PDE.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [November 29, 2019, 10:31pm UTC](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609/32 "2019-11-29T22:31:30Z")

</div>

A key point might be that integer division of a low negative number goes to 0, the floor of 0 is 0. Float division of a low negative number gives a low negative fraction – the floor of that is -1.

```auto
println(floor(1/60)); // floor( 0) = 0
println(floor(-1/60.0)); // floor(-0.016) = -1

```

So if iCompiler is treating accMin/60 like accMin/60.0, then when -1 \> accMin \> 0 then the code in PDE will return 0, and in iCompiler it will return -1. (untested)

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 30, 2019, 7:55pm UTC](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609/33 "2019-11-30T19:55:47Z")

</div>

I meant the PDE with IDE. The pseudo Code above was, because if forgot about Integer Division 😅

I edited my previous post to show a (more) correct version of what would happen, where the difference lies and that this is the case when using Integer Division.

[Previous page](https://discourse.processing.org/t/accumulate-rotation-with-snapping/15609.md?page=1)
