Modulus Math in Computational Layer

I was trying to figure out how to do a mod in CL.
In the calculator/graph, I think you can use mod(x,5)
Most languages I know use the % sign: example x % 5
Both of these so if a variable reaches the argument is “recycles to 0”.

Maybe there’s a documentation page somewhere related to this but couldn’t find it.

Thanks

The most reliable way (and the most efficient if you plan to call on it multiple times) is to use simpleFunction and evaluateAt. You can paste in an expression from the calculator of you’re not sure how to format the latex.
https://teacher.desmos.com/computation-layer/documentation#types:function:evaluateAt

There’s a shorter way using numericValue, but interpolating the numeric values as a string can lead to some errors depending on the Possible input values

If you know the syntax in a graph, you can copy/paste from the graph to the CL to see how it should be formatted in CL.

Thanks,
Here’s roughly what I did.

#Changes label on point A to the modulus of a divided by b
mod = simpleFunction("\mod(a,b)",“a”,“b”)
pointLabel(“A”):"${mod.evaluateAt(numericValue(exp1.content),numericValue(exp2.content))}"

1 Like

That works. Personally, I’d flip flop a little:

a=numericValue(exp1.content)
b=numericValue(exp2.content)
pointlabel("A"): "${simpleFunction("\mod(a,b)")}"

More lines, but looks less complicated to me. *shrug
Also, “.content”? Normally I’d use “.latex” or just numericValue(exp1), but guess it doesn’t matter.