track total size of static array and Unit/Class/Func
[hiphop-php.git] / hphp / runtime / base / double-to-int64.h
blob16abc2d67e05777d68dead3ff3a2c474d191f45e
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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_
20 #include <limits>
22 #include <folly/CPortability.h>
24 namespace HPHP {
26 ///////////////////////////////////////////////////////////////////////////////
28 inline int64_t double_to_int64(double v)
29 FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER("float-cast-overflow") {
30 if (v >= 0) {
31 return v < std::numeric_limits<uint64_t>::max() ? (uint64_t)v : 0u;
32 } else if (v < 0) {
33 return (int64_t)v;
34 } else {
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 ///////////////////////////////////////////////////////////////////////////////
46 #endif