1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 // MOZ: This file is a merge of the relevant parts of all the platform-*.cc
29 // files in v8; the amount of code remaining was small enough that putting
30 // everything in a single file was easier, particularly because it means we
31 // can always compile this one file on every platform.
42 double ceiling(double x) {
43 #if defined(__APPLE__)
44 // Correct Mac OS X Leopard 'ceil' behavior.
46 // MOZ: This appears to be fixed in Mac OS X 10.5.8.
48 // MOZ: This fix is apprently also required for FreeBSD and OpenBSD, if we
49 // have to worry about them.
50 if (-1.0 < x && x < 0.0) {
61 // MOZ: These exit behaviours were copied from SpiderMonkey's JS_Assert()
66 * We used to call DebugBreak() on Windows, but amazingly, it causes
67 * the MSVS 2010 debugger not to be able to recover a call stack.
71 #elif defined(__APPLE__)
73 * On Mac OS X, Breakpad ignores signals. Only real Mach exceptions are
76 *((int *) NULL) = 0; /* To continue from here in GDB: "return" then "continue". */
77 raise(SIGABRT); /* In case above statement gets nixed by the optimizer. */
79 raise(SIGABRT); /* To continue from here in GDB: "signal 0". */
83 } } // namespace v8::internal
85 // Extra POSIX/ANSI routines for Win32 when when using Visual Studio C++. Please
86 // refer to The Open Group Base Specification for specification of the correct
87 // semantics for these functions.
88 // (http://www.opengroup.org/onlinepubs/000095399/)
93 // Classify floating point number - usually defined in math.h
94 int fpclassify(double x) {
95 // Use the MS-specific _fpclass() for classification.
96 int flags = _fpclass(x);
98 // Determine class. We cannot use a switch statement because
99 // the _FPCLASS_ constants are defined as flags.
100 if (flags & (_FPCLASS_PN | _FPCLASS_NN)) return FP_NORMAL;
101 if (flags & (_FPCLASS_PZ | _FPCLASS_NZ)) return FP_ZERO;
102 if (flags & (_FPCLASS_PD | _FPCLASS_ND)) return FP_SUBNORMAL;
103 if (flags & (_FPCLASS_PINF | _FPCLASS_NINF)) return FP_INFINITE;
105 // All cases should be covered by the code above.
106 ASSERT(flags & (_FPCLASS_SNAN | _FPCLASS_QNAN));
117 // Classify floating point number
118 int fpclassify(double x) {
120 fpclass_t rv = fpclass(x);
124 case FP_QNAN: return FP_NAN;
126 case FP_PINF: return FP_INFINITE;
128 case FP_PDENORM: return FP_SUBNORMAL;
130 case FP_PZERO: return FP_ZERO;
132 ASSERT(rv == FP_NNORM || rv == FP_PNORM);