guest wrote: ↑Fri 23 Nov 2018, 18:42

Code: Select all

```
DEF FNfmod(x,y)
LOCAL n%
n%=x/y
=x-y*n%
```

If you can justify omitting the LOCAL statement (so that n% becomes a global) the benefit is even greater.

The x/y is only used once, and without side effects, so - if x and y are always positive - you could do:

And, as previously mentioned, for the greatest speed, inline it. Instead of

**z=FNfmod(a,b)** do

**z=a-b*INT(a/b)**, with the disdvantage of losing the coding symantics that tells you what it's doing.

If x or y could be negative you need to use the n%= method to truncate the integer towards zero, INT truncates the integer towards negative infinity.