/pliant/graphic/misc/float.pli
 
 1  abstract 
 2    [A few floatting point utility functions, that should stand elsewhere.] 
 3   
 4  # Copyright  Hubert Tonneau  hubert.tonneau@pliant.cx 
 5  # 
 6  # This program is free software; you can redistribute it and/or 
 7  # modify it under the terms of the GNU General Public License version 2 
 8  # as published by the Free Software Foundation. 
 9  # 
 10  # This program is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  # GNU General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU General Public License 
 16  # version 2 along with this program; if not, write to the Free Software 
 17  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 18   
 19   
 20  function compute_float_max -> f 
 21    arg Float f 
 22    := 1 
 23    var Float := 256 
 24    while s>1 
 25      if f*s=defined 
 26        *= s 
 27      else 
 28        /= 2 
 29   
 30  public 
 31   
 32  constant float_max compute_float_max 
 33  constant float_min -float_max 
 34   
 35  function bound f mini maxi -> b 
 36    arg Float mini maxi b 
 37    := shunt f<mini mini f>maxi maxi f 
 38   
 39  function pow2 x -> y 
 40    arg Float y 
 41    := x*x