Changeset 29243 in webkit for trunk/JavaScriptCore/kjs/value.cpp
- Timestamp:
- Jan 7, 2008, 1:50:51 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/value.cpp
r27747 r29243 2 2 * Copyright (C) 1999-2001 Harri Porten ([email protected]) 3 3 * Copyright (C) 2001 Peter Kelly ([email protected]) 4 * Copyright (C) 2003, 2007 Apple Inc. All rights reserved.4 * Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 31 31 32 32 namespace KJS { 33 34 #if defined NAN && defined INFINITY 35 36 extern const double NaN = NAN; 37 extern const double Inf = INFINITY; 38 39 #else // !(defined NAN && defined INFINITY) 40 41 // The trick is to define the NaN and Inf globals with a different type than the declaration. 42 // This trick works because the mangled name of the globals does not include the type, although 43 // I'm not sure that's guaranteed. There could be alignment issues with this, since arrays of 44 // characters don't necessarily need the same alignment doubles do, but for now it seems to work. 45 // It would be good to figure out a 100% clean way that still avoids code that runs at init time. 46 47 // Note, we have to use union to ensure alignment. Otherwise, NaN_Bytes can start anywhere, 48 // while NaN_double has to be 4-byte aligned for 32-bits. 49 // With -fstrict-aliasing enabled, unions are the only safe way to do type masquerading. 50 51 static const union { 52 struct { 53 unsigned char NaN_Bytes[8]; 54 unsigned char Inf_Bytes[8]; 55 } bytes; 56 57 struct { 58 double NaN_Double; 59 double Inf_Double; 60 } doubles; 61 62 } NaNInf = { { 63 #if PLATFORM(BIG_ENDIAN) 64 { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 }, 65 { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 } 66 #elif PLATFORM(MIDDLE_ENDIAN) 67 { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 }, 68 { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 } 69 #else 70 { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f }, 71 { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } 72 #endif 73 } } ; 74 75 extern const double NaN = NaNInf.doubles.NaN_Double; 76 extern const double Inf = NaNInf.doubles.Inf_Double; 77 78 #endif // !(defined NAN && defined INFINITY) 33 79 34 80 static const double D16 = 65536.0;
Note:
See TracChangeset
for help on using the changeset viewer.