Mercurial > octave-nkf
annotate liboctave/lo-ieee.cc @ 11234:2718e1fdf82f
IEEE math initialization tweaks
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Nov 2010 21:52:51 -0500 |
parents | 9c6143abf9e1 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
1967 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
9592
5828d64ca004
lo-ieee.cc: include cstdlib, update copyright date
John W. Eaton <jwe@octave.org>
parents:
9591
diff
changeset
|
4 2007, 2008, 2009 John W. Eaton |
1967 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1967 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1967 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
9592
5828d64ca004
lo-ieee.cc: include cstdlib, update copyright date
John W. Eaton <jwe@octave.org>
parents:
9591
diff
changeset
|
28 #include <cstdlib> |
1967 | 29 |
11234
2718e1fdf82f
IEEE math initialization tweaks
John W. Eaton <jwe@octave.org>
parents:
11230
diff
changeset
|
30 #include <limits> |
2508 | 31 |
4698 | 32 #include "lo-error.h" |
1967 | 33 #include "lo-ieee.h" |
4025 | 34 #include "mach-info.h" |
1967 | 35 |
36 void | |
37 octave_ieee_init (void) | |
38 { | |
4601 | 39 oct_mach_info::float_format ff = oct_mach_info::native_float_format (); |
40 | |
4698 | 41 switch (ff) |
4601 | 42 { |
4698 | 43 case oct_mach_info::flt_fmt_ieee_big_endian: |
44 case oct_mach_info::flt_fmt_ieee_little_endian: | |
45 { | |
11234
2718e1fdf82f
IEEE math initialization tweaks
John W. Eaton <jwe@octave.org>
parents:
11230
diff
changeset
|
46 octave_NaN = std::numeric_limits<double>::quiet_NaN (); |
2718e1fdf82f
IEEE math initialization tweaks
John W. Eaton <jwe@octave.org>
parents:
11230
diff
changeset
|
47 octave_Inf = std::numeric_limits<double>::infinity (); |
1967 | 48 |
11234
2718e1fdf82f
IEEE math initialization tweaks
John W. Eaton <jwe@octave.org>
parents:
11230
diff
changeset
|
49 octave_Float_NaN = std::numeric_limits<float>::quiet_NaN (); |
2718e1fdf82f
IEEE math initialization tweaks
John W. Eaton <jwe@octave.org>
parents:
11230
diff
changeset
|
50 octave_Float_Inf = std::numeric_limits<float>::infinity (); |
1967 | 51 |
11234
2718e1fdf82f
IEEE math initialization tweaks
John W. Eaton <jwe@octave.org>
parents:
11230
diff
changeset
|
52 // The following is patterned after code in R. |
4698 | 53 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
54 if (ff == oct_mach_info::flt_fmt_ieee_big_endian) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
55 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
56 lo_ieee_hw = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
57 lo_ieee_lw = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
58 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
59 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
60 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
61 lo_ieee_hw = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
62 lo_ieee_lw = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
63 } |
4025 | 64 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
65 lo_ieee_double t; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
66 t.word[lo_ieee_hw] = LO_IEEE_NA_HW; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
67 t.word[lo_ieee_lw] = LO_IEEE_NA_LW; |
4698 | 68 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
69 octave_NA = t.value; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
70 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
71 lo_ieee_float tf; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
72 tf.word = LO_IEEE_NA_FLOAT; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
73 octave_Float_NA = tf.value; |
4698 | 74 } |
75 break; | |
4025 | 76 |
4698 | 77 case oct_mach_info::flt_fmt_cray: |
78 case oct_mach_info::flt_fmt_vax_d: | |
79 case oct_mach_info::flt_fmt_vax_g: | |
80 default: | |
81 // If the format is unknown, then you will probably not have a | |
9805
bb70d16cca3b
fail at configure time if IEEE floating point format is not detected
John W. Eaton <jwe@octave.org>
parents:
9592
diff
changeset
|
82 // useful system, so we will abort here. Anyone wishing to |
bb70d16cca3b
fail at configure time if IEEE floating point format is not detected
John W. Eaton <jwe@octave.org>
parents:
9592
diff
changeset
|
83 // experiment with building Octave on a system without IEEE |
bb70d16cca3b
fail at configure time if IEEE floating point format is not detected
John W. Eaton <jwe@octave.org>
parents:
9592
diff
changeset
|
84 // floating point should be capable of removing this check and |
bb70d16cca3b
fail at configure time if IEEE floating point format is not detected
John W. Eaton <jwe@octave.org>
parents:
9592
diff
changeset
|
85 // the configure test. |
9591
264fb5520973
abort if floating point format is not recognized as IEEE
John W. Eaton <jwe@octave.org>
parents:
9441
diff
changeset
|
86 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
87 ("lo_ieee_init: floating point format is not IEEE! Maybe DLAMCH is miscompiled, or you are using some strange system without IEEE floating point math?"); |
9591
264fb5520973
abort if floating point format is not recognized as IEEE
John W. Eaton <jwe@octave.org>
parents:
9441
diff
changeset
|
88 abort (); |
4601 | 89 } |
1967 | 90 } |