MySQL 8.4.0
Source Code Documentation
my_double2ulonglong.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2016, 2024, 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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
24
25#ifndef MY_DOUBLE2ULONGLONG_INCLUDED
26#define MY_DOUBLE2ULONGLONG_INCLUDED
27
28/**
29 @file include/my_double2ulonglong.h
30 Utility functions for converting between ulonglong and double.
31*/
32
33#include "my_inttypes.h"
34
35#ifdef _WIN32
36inline unsigned long long my_double2ulonglong(double d) {
37 const double t = d - (double)0x8000000000000000ULL;
38
39 if (t >= 0) return ((unsigned long long)t) + 0x8000000000000000ULL;
40 return (unsigned long long)d;
41}
42#define double2ulonglong my_double2ulonglong
43#endif /* _WIN32 */
44
45#ifndef ulonglong2double
46#define ulonglong2double(A) ((double)(ulonglong)(A))
47#define my_off_t2double(A) ((double)(my_off_t)(A))
48#endif
49#ifndef double2ulonglong
50#define double2ulonglong(A) ((ulonglong)(double)(A))
51#endif
52
53// The largest longlong that will fix into a double (LLONG_MAX is not
54// exactly convertible to double, so for large double x, the test
55// x <= LLONG_MAX does not guarantee x will fit in a longlong,
56// and may give a compiler warning). LLONG_MIN is exact.
57static constexpr double LLONG_MAX_DOUBLE = 9223372036854774784.0;
58
59// Similar, for ulonglong.
60static constexpr double ULLONG_MAX_DOUBLE = 18446744073709549568.0;
61
62// The largest and smallest integer that is guaranteed to fix exactly into a
63// double (there are 53 mantissa bits).
64static constexpr int64_t MAX_EXACT_INTEGER_DOUBLE = (1ULL << 53);
66
67// Same, for float.
68static constexpr int64_t MAX_EXACT_INTEGER_FLOAT = (1ULL << 23);
70
71#endif // MY_DOUBLE2ULONGLONG_INCLUDED
static constexpr int64_t MIN_EXACT_INTEGER_FLOAT
Definition: my_double2ulonglong.h:69
static constexpr double LLONG_MAX_DOUBLE
Definition: my_double2ulonglong.h:57
static constexpr double ULLONG_MAX_DOUBLE
Definition: my_double2ulonglong.h:60
static constexpr int64_t MAX_EXACT_INTEGER_DOUBLE
Definition: my_double2ulonglong.h:64
static constexpr int64_t MAX_EXACT_INTEGER_FLOAT
Definition: my_double2ulonglong.h:68
static constexpr int64_t MIN_EXACT_INTEGER_DOUBLE
Definition: my_double2ulonglong.h:65
Some integer typedefs for easier portability.