146686Sbrian/* Floating point definitions for GDB.
246686Sbrian
346686Sbrian   Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
446686Sbrian   1996, 1997, 1998, 1999, 2000, 2001, 2003 Free Software Foundation,
546686Sbrian   Inc.
646686Sbrian
746686Sbrian   This file is part of GDB.
846686Sbrian
946686Sbrian   This program is free software; you can redistribute it and/or modify
1046686Sbrian   it under the terms of the GNU General Public License as published by
1146686Sbrian   the Free Software Foundation; either version 2 of the License, or
1246686Sbrian   (at your option) any later version.
1346686Sbrian
1446686Sbrian   This program is distributed in the hope that it will be useful,
1546686Sbrian   but WITHOUT ANY WARRANTY; without even the implied warranty of
1646686Sbrian   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1746686Sbrian   GNU General Public License for more details.
1846686Sbrian
1946686Sbrian   You should have received a copy of the GNU General Public License
2046686Sbrian   along with this program; if not, write to the Free Software
2146686Sbrian   Foundation, Inc., 59 Temple Place - Suite 330,
2246686Sbrian   Boston, MA 02111-1307, USA.  */
2346686Sbrian
2446686Sbrian#ifndef DOUBLEST_H
2546686Sbrian#define DOUBLEST_H
2650479Speter
2746686Sbrianstruct type;
2846686Sbrian
2946686Sbrian/* Setup definitions for host and target floating point formats.  We need to
3046686Sbrian   consider the format for `float', `double', and `long double' for both target
3146686Sbrian   and host.  We need to do this so that we know what kind of conversions need
3246686Sbrian   to be done when converting target numbers to and from the hosts DOUBLEST
3346686Sbrian   data type.  */
3446686Sbrian
3546686Sbrian/* This is used to indicate that we don't know the format of the floating point
3646686Sbrian   number.  Typically, this is useful for native ports, where the actual format
3746686Sbrian   is irrelevant, since no conversions will be taking place.  */
3846686Sbrian
3946686Sbrian#include "floatformat.h"	/* For struct floatformat */
4046686Sbrian
4146686Sbrian/* Use `long double' if the host compiler supports it.  (Note that this is not
4246686Sbrian   necessarily any longer than `double'.  On SunOS/gcc, it's the same as
4346686Sbrian   double.)  This is necessary because GDB internally converts all floating
4446686Sbrian   point values to the widest type supported by the host.
4546686Sbrian
4646686Sbrian   There are problems however, when the target `long double' is longer than the
4746686Sbrian   host's `long double'.  In general, we'll probably reduce the precision of
4846686Sbrian   any such values and print a warning.  */
4946686Sbrian
5046686Sbrian#ifdef HAVE_LONG_DOUBLE
5146686Sbriantypedef long double DOUBLEST;
52134789Sbrian#else
53134789Sbriantypedef double DOUBLEST;
5447061Sbrian#endif
5547061Sbrian
5654912Sbrianextern void floatformat_to_doublest (const struct floatformat *,
57131327Sbrian				     const void *in, DOUBLEST *out);
5847061Sbrianextern void floatformat_from_doublest (const struct floatformat *,
5947061Sbrian				       const DOUBLEST *in, void *out);
6047061Sbrian
6147061Sbrianextern int floatformat_is_negative (const struct floatformat *, char *);
62134789Sbrianextern int floatformat_is_nan (const struct floatformat *, char *);
63134789Sbrianextern char *floatformat_mantissa (const struct floatformat *, char *);
6446686Sbrian
6546686Sbrian/* These functions have been replaced by extract_typed_floating and
66131327Sbrian   store_typed_floating.
6746686Sbrian
6846686Sbrian   Most calls are passing in TYPE_LENGTH (TYPE) so can be changed to
6946686Sbrian   just pass the TYPE.  The remainder pass in the length of a
7046686Sbrian   register, those calls should instead pass in the floating point
7147061Sbrian   type that corresponds to that length.  */
7247061Sbrian
7347061Sbrianextern DOUBLEST deprecated_extract_floating (const void *addr, int len);
74131327Sbrianextern void deprecated_store_floating (void *addr, int len, DOUBLEST val);
75131327Sbrian
76131327Sbrian/* Given TYPE, return its floatformat.  TYPE_FLOATFORMAT() may return
77131327Sbrian   NULL.  type_floatformat() detects that and returns a floatformat
7854912Sbrian   based on the type size when FLOATFORMAT is NULL.  */
7946686Sbrian
8046686Sbrianconst struct floatformat *floatformat_from_type (const struct type *type);
8146686Sbrian
8246686Sbrianextern DOUBLEST extract_typed_floating (const void *addr,
8346686Sbrian					const struct type *type);
8447062Sbrianextern void store_typed_floating (void *addr, const struct type *type,
85				  DOUBLEST val);
86extern void convert_typed_floating (const void *from,
87				    const struct type *from_type,
88                                    void *to, const struct type *to_type);
89
90#endif
91