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 | // Note, we have to use union to ensure alignment. Otherwise, NaN_Bytes can start anywhere,
|
---|
50 | // while NaN_double has to be 4-byte aligned for 32-bits.
|
---|
51 | // With -fstrict-aliasing enabled, unions are the only safe way to do type masquerading.
|
---|
52 |
|
---|
53 | static const union {
|
---|
54 | struct {
|
---|
55 | unsigned char NaN_Bytes[8];
|
---|
56 | unsigned char Inf_Bytes[8];
|
---|
57 | } bytes;
|
---|
58 |
|
---|
59 | struct {
|
---|
60 | double NaN_Double;
|
---|
61 | double Inf_Double;
|
---|
62 | } doubles;
|
---|
63 |
|
---|
64 | } NaNInf = { {
|
---|
65 | #if PLATFORM(BIG_ENDIAN)
|
---|
66 | { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 },
|
---|
67 | { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 }
|
---|
68 | #elif PLATFORM(MIDDLE_ENDIAN)
|
---|
69 | { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 },
|
---|
70 | { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 }
|
---|
71 | #else
|
---|
72 | { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f },
|
---|
73 | { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f }
|
---|
74 | #endif
|
---|
75 | } } ;
|
---|
76 |
|
---|
77 | extern const double NaN = NaNInf.doubles.NaN_Double;
|
---|
78 | extern const double Inf = NaNInf.doubles.Inf_Double;
|
---|
79 |
|
---|
80 | #endif // !PLATFORM(DARWIN)
|
---|
81 |
|
---|
82 |
|
---|
83 | } // namespace KJS
|
---|