Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
floating_point_win.cc
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "platform/globals.h"
6#if defined(DART_HOST_OS_WINDOWS)
7
9
10#include <limits> // NOLINT
11
12// Taken from third_party/v8/src/platform-win32.cc
13double fmod_ieee(double x, double y) {
14 // x is dividend, y is divisor.
15 // Work around MS fmod bugs. ISO Standard says:
16 // If dividend is finite and divisor is an infinity or
17 // dividend is a zero and divisor is nonzero finite,
18 // then dividend is returned.
19 if (!(_finite(x) && (!_finite(y) && !isnan(y))) &&
20 !(x == 0 && (y != 0 && _finite(y)))) {
21 x = fmod(x, y);
22 }
23 return x;
24}
25
26// Bring MSVC atan2 behavior in line with ISO standard.
27// MSVC atan2 returns NaN when x and y are either +infinity or -infinity.
28// Per ISO standard:
29// - If y is +/-infinity and x is -infinity, +/-3*pi/4 is returned.
30// - If y is +/-infinity and x is +infinity, +/-pi/4 is returned.
31double atan2_ieee(double x, double y) {
32 int cls_x = _fpclass(x);
33 int cls_y = _fpclass(y);
34 if (((cls_x & (_FPCLASS_PINF | _FPCLASS_NINF)) != 0) &&
35 ((cls_y & (_FPCLASS_PINF | _FPCLASS_NINF)) != 0)) {
36 // atan2 values at infinities listed above are the same as values at (+/-1,
37 // +/-1). index_x is 0, when x is +infinity, 1 when x is -infinity. Same is
38 // with index_y.
39 int index_x = (cls_x & _FPCLASS_PINF) != 0 ? 0 : 1;
40 int index_y = (cls_y & _FPCLASS_PINF) != 0 ? 0 : 1;
41 static double atans_at_infinities[2][2] = {
42 {atan2(1., 1.), atan2(1., -1.)}, {atan2(-1., 1.), atan2(-1., -1.)}};
43 return atans_at_infinities[index_x][index_y];
44 } else {
45 return atan2(x, y);
46 }
47}
48
49#endif // defined(DART_HOST_OS_WINDOWS)
double y
double x
double fmod_ieee(double x, double y)
double atan2_ieee(double y, double x)