2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_DOUBLE_TO_INT64_H_
18 #define incl_HPHP_DOUBLE_TO_INT64_H_
22 #include <folly/CPortability.h>
26 ///////////////////////////////////////////////////////////////////////////////
28 inline int64_t double_to_int64(double v
)
29 FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER("float-cast-overflow") {
31 return v
< std::numeric_limits
<uint64_t>::max() ? (uint64_t)v
: 0u;
35 // If v >= 0 is false and v < 0 is false, then v is NaN. In PHP5, on Intel,
36 // you get 0x800..00, a.k.a. the minimum int64_t.
37 // We mimic that on all platforms, though this makes us sad.
38 return std::numeric_limits
<int64_t>::min();
42 ///////////////////////////////////////////////////////////////////////////////