MySQL 8.0.29
Source Code Documentation
my_double2ulonglong.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2016, 2021, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MY_DOUBLE2ULONGLONG_INCLUDED
25#define MY_DOUBLE2ULONGLONG_INCLUDED
26
27/**
28 @file include/my_double2ulonglong.h
29 Utility functions for converting between ulonglong and double.
30*/
31
32#include "my_inttypes.h"
33
34#ifdef _WIN32
35inline unsigned long long my_double2ulonglong(double d) {
36 double t = d - (double)0x8000000000000000ULL;
37
38 if (t >= 0) return ((unsigned long long)t) + 0x8000000000000000ULL;
39 return (unsigned long long)d;
40}
41#define double2ulonglong my_double2ulonglong
42#endif /* _WIN32 */
43
44#ifndef ulonglong2double
45#define ulonglong2double(A) ((double)(ulonglong)(A))
46#define my_off_t2double(A) ((double)(my_off_t)(A))
47#endif
48#ifndef double2ulonglong
49#define double2ulonglong(A) ((ulonglong)(double)(A))
50#endif
51
52// The largest longlong that will fix into a double (LLONG_MAX is not
53// exactly convertible to double, so for large double x, the test
54// x <= LLONG_MAX does not guarantee x will fit in a longlong,
55// and may give a compiler warning). LLONG_MIN is exact.
56static constexpr double LLONG_MAX_DOUBLE = 9223372036854774784.0;
57
58// Similar, for ulonglong.
59static constexpr double ULLONG_MAX_DOUBLE = 18446744073709549568.0;
60
61// The largest and smallest integer that is guaranteed to fix exactly into a
62// double (there are 53 mantissa bits).
63static constexpr int64_t MAX_EXACT_INTEGER_DOUBLE = (1ULL << 53);
65
66// Same, for float.
67static constexpr int64_t MAX_EXACT_INTEGER_FLOAT = (1ULL << 23);
69
70#endif // MY_DOUBLE2ULONGLONG_INCLUDED
static constexpr int64_t MIN_EXACT_INTEGER_FLOAT
Definition: my_double2ulonglong.h:68
static constexpr double LLONG_MAX_DOUBLE
Definition: my_double2ulonglong.h:56
static constexpr double ULLONG_MAX_DOUBLE
Definition: my_double2ulonglong.h:59
static constexpr int64_t MAX_EXACT_INTEGER_DOUBLE
Definition: my_double2ulonglong.h:63
static constexpr int64_t MAX_EXACT_INTEGER_FLOAT
Definition: my_double2ulonglong.h:67
static constexpr int64_t MIN_EXACT_INTEGER_DOUBLE
Definition: my_double2ulonglong.h:64
Some integer typedefs for easier portability.