Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Mathematical functions

Peter Tillema edited this page Sep 15, 2018 · 4 revisions

ICE supports a few of the math functions you can find in TI-OS (though a few have different syntax), they are:

Function Explanation
not(EXP) Returns the negation of EXP.
remainder(EXP1,EXP2) Returns the remainder when EXP1 is divided by EXP2.
min(EXP1,EXP2) Returns the smaller value of EXP1 and EXP2.
max(EXP1,EXP2) Returns the larger value of EXP1 and EXP2.
mean(EXP1,EXP2) Returns the mean (average) value of EXP1 and EXP2.
sqrt(EXP) Returns the square root of EXP.
sin(EXP) Returns the sine root of EXP. Input EXP should be a value between 0 and 255 (split the circle into 256 equal sections) and will return a value between -255 and 255.
cos(EXP) Returns the cosine root of EXP. Input EXP should be a value between 0 and 255 (split the circle into 256 equal sections) and will return a value between -255 and 255.

Note: all results will be truncated!

Examples:

Code Result Explanation
remainder(10,3) 1 3 goes into 10 only 3 whole times, with 1 leftover.
remainder(64,10) 4 10 goes into 64 only 6 whole times, with 4 leftover.
remainder(10,5) 0 5 goes into 10 exactly 2 whole times, with 0 leftover.
min(5,2) 2 2 is less than 5.
min(123,120) 120 120 is less than 123.
min(10,10) 10 10 is equal to 10.
max(5,2) 5 5 is greater than 2.
max(123,120) 123 123 is greater than 120.
max(10,10) 10 10 is equal to 10.
mean(22,20) 21 (22+20)/2 = 21.
mean(64,20) 42 (64+20)/2 = 42.
mean(5,8) 6 (5+8)/2 = 6.5, truncated = 6.
sqrt(25) 5 √25 = 5.
sqrt(120) 10 √120 ≈ 10.954, truncated = 10.
sqrt(2) 1 √2 ≈ 1.414, truncated = 1.
sin(2) 12 255*sin(2/256*2*π) ≈ 12.51, truncated = 12.
sin(120) 49 255*sin(120/256*2*π) ≈ 49.75, truncated = 49.
sin(255) 16777210 255*sin(255/256*2*π) ≈ -6.26, truncated = -6.
cos(2) 254 255*cos(2/256*2*π) ≈ 254.69, truncated = 254.
cos(120) 16776966 255*cos(120/256*2*π) ≈ -250.10, truncated = -250.
cos(255) 254 255*cos(255/256*2*π) ≈ 254.92, truncated = 254.
Clone this wiki locally