1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Extra POSIX/ANSI routines for Win32 when using Visual Studio C++. Please
6 // refer to The Open Group Base Specification for specification of the correct
7 // semantics for these functions.
8 // (http://www.opengroup.org/onlinepubs/000095399/)
9 #if defined(_MSC_VER) && (_MSC_VER < 1800)
11 #include "src/base/win32-headers.h"
12 #include <float.h> // Required for DBL_MAX and on Win32 for finite()
13 #include <limits.h> // Required for INT_MAX etc.
15 #include "src/base/win32-math.h"
17 #include "src/base/logging.h"
22 // Test for a NaN (not a number) value - usually defined in math.h
28 // Test for infinity - usually defined in math.h
30 return (_fpclass(x) & (_FPCLASS_PINF | _FPCLASS_NINF)) != 0;
34 // Test for finite value - usually defined in math.h
35 int isfinite(double x) {
40 // Test if x is less than y and both nominal - usually defined in math.h
41 int isless(double x, double y) {
42 return isnan(x) || isnan(y) ? 0 : x < y;
46 // Test if x is greater than y and both nominal - usually defined in math.h
47 int isgreater(double x, double y) {
48 return isnan(x) || isnan(y) ? 0 : x > y;
52 // Classify floating point number - usually defined in math.h
53 int fpclassify(double x) {
54 // Use the MS-specific _fpclass() for classification.
55 int flags = _fpclass(x);
57 // Determine class. We cannot use a switch statement because
58 // the _FPCLASS_ constants are defined as flags.
59 if (flags & (_FPCLASS_PN | _FPCLASS_NN)) return FP_NORMAL;
60 if (flags & (_FPCLASS_PZ | _FPCLASS_NZ)) return FP_ZERO;
61 if (flags & (_FPCLASS_PD | _FPCLASS_ND)) return FP_SUBNORMAL;
62 if (flags & (_FPCLASS_PINF | _FPCLASS_NINF)) return FP_INFINITE;
64 // All cases should be covered by the code above.
65 DCHECK(flags & (_FPCLASS_SNAN | _FPCLASS_QNAN));
70 // Test sign - usually defined in math.h
71 int signbit(double x) {
72 // We need to take care of the special case of both positive
73 // and negative versions of zero.
75 return _fpclass(x) & _FPCLASS_NZ;