2 * $Id: ftype-double.c,v 1.7 2002/08/28 20:41:00 jmayer Exp $
4 * Ethereal - Network traffic analyzer
5 * By Gerald Combs <gerald@ethereal.com>
6 * Copyright 2001 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <ftypes-int.h>
33 double_fvalue_new(fvalue_t *fv)
35 fv->value.floating = 0.0;
39 double_fvalue_set_floating(fvalue_t *fv, gdouble value)
41 fv->value.floating = value;
45 value_get_floating(fvalue_t *fv)
47 return fv->value.floating;
51 val_from_string(fvalue_t *fv, char *s, LogFunc logfunc)
55 fv->value.floating = strtod(s, &endptr);
57 if (endptr == s || *endptr != '\0') {
58 /* This isn't a valid number. */
59 logfunc("\"%s\" is not a valid number.", s);
62 if (errno == ERANGE) {
63 if (fv->value.floating == 0) {
64 logfunc("\"%s\" causes floating-point underflow.", s);
66 else if (fv->value.floating == HUGE_VAL) {
67 logfunc("\"%s\" causes floating-point overflow.", s);
70 logfunc("\"%s\" is not a valid floating-point number.",
81 cmp_eq(fvalue_t *a, fvalue_t *b)
83 return a->value.floating == b->value.floating;
87 cmp_ne(fvalue_t *a, fvalue_t *b)
89 return a->value.floating != b->value.floating;
93 cmp_gt(fvalue_t *a, fvalue_t *b)
95 return a->value.floating > b->value.floating;
99 cmp_ge(fvalue_t *a, fvalue_t *b)
101 return a->value.floating >= b->value.floating;
105 cmp_lt(fvalue_t *a, fvalue_t *b)
107 return a->value.floating < b->value.floating;
111 cmp_le(fvalue_t *a, fvalue_t *b)
113 return a->value.floating <= b->value.floating;
117 ftype_register_double(void)
120 static ftype_t float_type = {
122 "floating point (single-precision)",
130 double_fvalue_set_floating,
147 static ftype_t double_type = {
149 "floating point (double-precision)",
157 double_fvalue_set_floating,
174 ftype_register(FT_FLOAT, &float_type);
175 ftype_register(FT_DOUBLE, &double_type);