Build the blancmange function The blancmange function is used as an example in basic calculus of a function that is continuous everywhere, but differentiable nowhere. It achieves this effect by using  the sums of ever-diminishing triangle-wave functions.

Your task is to build a program that takes a binary fractional number in the interval [0, 1] and returns the exact height of the blancmange curve at that position. Both fractions can be represented using the notation of your choice, but if you are using a nonstandard one (e.g. not IEEE floating-point or an integer with a fixed radix point), you must explain it in your solution, and your notation must support an accuracy of at least 2-52.
Ruby, 53 characters

f=-&gt;x{x&gt;0?f[2*x=x&lt;0.5?x:1-x]/2+x: 0}
$&gt;&lt;&lt;f[gets.to_f]


expanded:

f = lambda do |x|
  if i&gt;0
    x = 1 - x unless x &lt; 0.5
    return x + f[2*x] / 2
  else
    return 0
  end
end  

print f[gets.to_f]


The input is a decimal value, assumed to be in the range 0..1 . The output is a decimal value. The platform native double precision numeric type is used, and is assumed to be at least 53 bits of mantissa. Since every floating point value in a binary fraction, this algorithm will always terminate after at most 53 (with the default precision) steps.