frac

func frac(n : Number) -> Number
  return n - int(n)

Returns the fractional part of the given number, preserving the sign. For example:
  frac(1.9) = 0.9
  frac(-1.9) = -0.9
Note that, due to round-off errors in the decimal to binary conversion, the fractions resulting from frac are not always exactly equal to the fractions obtained when the decimal answer is converted to binary. For example:
  frac(1.1) /= 0.1
This violates the author's expectations, particularly since the difference between frac(1.1) and 0.1 are rounded away when they are converted to decimal. For example:
  mkstr(frac(1.1)) = mkstr(0.1) = `0.1'
However, the author does not know enough about floating point issues to address this problem, and does not have the time either. Meanwhile, explicit rounding can be used to discard the least significant digit(s), before comparing.

See also: abs, ceil, floor, int, round, sign


Herman Venter

This is Slim documentation as snarfed on 27 May 1999 by dB.