-- Frac library (movie script) ---------------------------------------- -- Shortcut for creating 'frac' values -- @param {integer} numerator -- @param {integer} denominator -- @return {instance} ---------------------------------------- on frac (numerator, denominator) return script("Frac").new(numerator, denominator) end ---------------------------------------- -- All functions below this comment only support 'fracs', i.e. instances -- of the Frac Class, as arguments. An integer n is casted to frac via frac(n). ---------------------------------------- -- Optionally supports more than 2 arguments on fAdd (a, b) -- ... res = a repeat with i = 2 to the paramCount p = param(i) num = res.num * p.denom + res.denom * p.num denom = res.denom * p.denom res = frac(num, denom) end repeat return res end on fSub (a, b) return frac(a.num * b.den - a.den * b.num, a.den * b.den) end -- Optionally supports more than 2 arguments on fMul (a, b) -- ... res = a repeat with i = 2 to the paramCount p = param(i) res = frac(res.num * p.num, res.denom * p.denom) end repeat return res end on fDiv (a, b) return frac(a.num * b.denom, a.denom * b.num) end on fAbs (f) return frac(abs(f.num), f.denom) end on fNeg (f) return frac(-f.num, f.denom) end on fEQ (a, b) diff = fSub(a, b) return diff.num=0 end on fNE (a, b) return not fEQ (a, b) end on fGT (a, b) diff = fSub(a, b) return diff.num>0 end on fLT (a, b) diff = fSub(a, b) return diff.num<0 end on fGE (a, b) diff = fSub(a, b) return diff.num>=0 end on fLE (a, b) diff = fSub(a, b) return diff.num<=0 end