1 | /*
|
---|
2 | * Copyright (C) 2003, 2006 Apple Computer, Inc.
|
---|
3 | *
|
---|
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.
|
---|
8 | *
|
---|
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.
|
---|
13 | *
|
---|
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,
|
---|
17 | * USA.
|
---|
18 | *
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "config.h"
|
---|
22 |
|
---|
23 | namespace KJS {
|
---|
24 |
|
---|
25 | // This file exists because JavaScriptCore needs to define the NaN and Inf globals in a way
|
---|
26 | // that does not use a static initializer so we don't have a framework initialization routine.
|
---|
27 |
|
---|
28 | // The trick is to define the NaN and Inf globals with a different type than the declaration.
|
---|
29 | // This trick works because the mangled name of the globals does not include the type, although
|
---|
30 | // I'm not sure that's guaranteed. There could be alignment issues with this, since arrays of
|
---|
31 | // characters don't necessarily need the same alignment doubles do, but for now it seems to work.
|
---|
32 | // It would be good to figure out a 100% clean way that still avoids code that runs at init time.
|
---|
33 |
|
---|
34 | #if PLATFORM(DARWIN)
|
---|
35 |
|
---|
36 | #if PLATFORM(BIG_ENDIAN)
|
---|
37 | extern const unsigned char NaN[sizeof(double)] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
|
---|
38 | extern const unsigned char Inf[sizeof(double)] = { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 };
|
---|
39 | #elif PLATFORM(MIDDLE_ENDIAN)
|
---|
40 | extern const unsigned char NaN[] = { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 };
|
---|
41 | extern const unsigned char Inf[] = { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 };
|
---|
42 | #else
|
---|
43 | extern const unsigned char NaN[sizeof(double)] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
|
---|
44 | extern const unsigned char Inf[sizeof(double)] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
|
---|
45 | #endif // PLATFORM(MIDDLE_ENDIAN)
|
---|
46 |
|
---|
47 | #else // !PLATFORM(DARWIN)
|
---|
48 |
|
---|
49 | #if PLATFORM(BIG_ENDIAN)
|
---|
50 | const unsigned char NaN_Bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
|
---|
51 | const unsigned char Inf_Bytes[] = { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 };
|
---|
52 | #elif PLATFORM(MIDDLE_ENDIAN)
|
---|
53 | const unsigned char NaN_Bytes[] = { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 };
|
---|
54 | const unsigned char Inf_Bytes[] = { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 };
|
---|
55 | #else
|
---|
56 | const unsigned char NaN_Bytes[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
|
---|
57 | const unsigned char Inf_Bytes[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
|
---|
58 | #endif
|
---|
59 | extern const double NaN = *(const double*) NaN_Bytes;
|
---|
60 | extern const double Inf = *(const double*) Inf_Bytes;
|
---|
61 |
|
---|
62 | #endif // !PLATFORM(DARWIN)
|
---|
63 |
|
---|
64 |
|
---|
65 | } // namespace KJS
|
---|