2 * Copyright (C) 2003, 2006 Apple Computer, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
26 // This file exists because JavaScriptCore needs to define the NaN and Inf globals in a way
27 // that does not use a static initializer so we don't have a framework initialization routine.
29 // The trick is to define the NaN and Inf globals with a different type than the declaration.
30 // This trick works because the mangled name of the globals does not include the type, although
31 // I'm not sure that's guaranteed. There could be alignment issues with this, since arrays of
32 // characters don't necessarily need the same alignment doubles do, but for now it seems to work.
33 // It would be good to figure out a 100% clean way that still avoids code that runs at init time.
35 #if (defined(AVOID_STATIC_CONSTRUCTORS) && !AVOID_STATIC_CONSTRUCTORS)
36 extern const double NaN
= NAN
;
37 extern const double Inf
= INFINITY
;
38 #elif PLATFORM(DARWIN)
40 #if PLATFORM(BIG_ENDIAN)
41 extern const unsigned char NaN
[sizeof(double)] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
42 extern const unsigned char Inf
[sizeof(double)] = { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 };
43 #elif PLATFORM(MIDDLE_ENDIAN)
44 extern const unsigned char NaN
[] = { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 };
45 extern const unsigned char Inf
[] = { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 };
47 extern const unsigned char NaN
[sizeof(double)] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
48 extern const unsigned char Inf
[sizeof(double)] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
49 #endif // PLATFORM(MIDDLE_ENDIAN)
51 #else // !PLATFORM(DARWIN)
53 #if PLATFORM(BIG_ENDIAN)
54 const unsigned char NaN_Bytes
[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
55 const unsigned char Inf_Bytes
[] = { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 };
56 #elif PLATFORM(MIDDLE_ENDIAN)
57 const unsigned char NaN_Bytes
[] = { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 };
58 const unsigned char Inf_Bytes
[] = { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 };
60 const unsigned char NaN_Bytes
[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
61 const unsigned char Inf_Bytes
[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
63 extern const double NaN
= *(const double*) NaN_Bytes
;
64 extern const double Inf
= *(const double*) Inf_Bytes
;
66 #endif // !PLATFORM(DARWIN)