/*
 * Some useful routines to do with numbers
 * Copyright (C) 2000 Andrew Hunter
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *  
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __number_h
#define __number_h

/*                          ----=====88888=====----                          */

union DoubleType
  {
    double d;

    /* This is the IEEE 754 double-precision format.  */
    struct
    {
      UInt32 sign : 1;
      UInt32 exp  : 11;
      UInt32 manH : 20;
      UInt32 manL;
    } bits;
    struct
    {
      UInt32 high;
      UInt32 low;
    } decompose;
  };

/*                          ----=====88888=====----                          */

/* _d_itod doesn't work (OS 3.1)... This does :-) */
extern double GetDouble(Int32 number);

/* Converts strings to doubles */
extern double StrToD   (Char* string);

typedef enum
{
  FormatFloat,
  FormatFixed,
  FormatExponent
} NumFormat;

/* Produce formatted numbers */
/*
 * (A description that really doesn't do the difficulty of the problem 
 * any justice...)
 *
 * Note that exponent format can be a little on the slow side
 */
extern void FormatDouble(double    number,
			 Char*     buffer,
			 UInt16    buflen,
			 NumFormat format,
			 UInt16    places);

#endif

