]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/double-conversion-diy-fp.cpp
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / double-conversion-diy-fp.cpp
CommitLineData
0f5d89e8
A
1// © 2018 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3//
4// From the double-conversion library. Original license:
5//
6// Copyright 2010 the V8 project authors. All rights reserved.
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions are
9// met:
10//
11// * Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// * Redistributions in binary form must reproduce the above
14// copyright notice, this list of conditions and the following
15// disclaimer in the documentation and/or other materials provided
16// with the distribution.
17// * Neither the name of Google Inc. nor the names of its
18// contributors may be used to endorse or promote products derived
19// from this software without specific prior written permission.
20//
21// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33// ICU PATCH: ifdef around UCONFIG_NO_FORMATTING
34#include "unicode/utypes.h"
35#if !UCONFIG_NO_FORMATTING
36
37// ICU PATCH: Customize header file paths for ICU.
38
39#include "double-conversion-diy-fp.h"
40#include "double-conversion-utils.h"
41
42// ICU PATCH: Wrap in ICU namespace
43U_NAMESPACE_BEGIN
44
45namespace double_conversion {
46
47void DiyFp::Multiply(const DiyFp& other) {
48 // Simply "emulates" a 128 bit multiplication.
49 // However: the resulting number only contains 64 bits. The least
50 // significant 64 bits are only used for rounding the most significant 64
51 // bits.
52 const uint64_t kM32 = 0xFFFFFFFFU;
53 uint64_t a = f_ >> 32;
54 uint64_t b = f_ & kM32;
55 uint64_t c = other.f_ >> 32;
56 uint64_t d = other.f_ & kM32;
57 uint64_t ac = a * c;
58 uint64_t bc = b * c;
59 uint64_t ad = a * d;
60 uint64_t bd = b * d;
61 uint64_t tmp = (bd >> 32) + (ad & kM32) + (bc & kM32);
62 // By adding 1U << 31 to tmp we round the final result.
63 // Halfway cases will be round up.
64 tmp += 1U << 31;
65 uint64_t result_f = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32);
66 e_ += other.e_ + 64;
67 f_ = result_f;
68}
69
70} // namespace double_conversion
71
72// ICU PATCH: Close ICU namespace
73U_NAMESPACE_END
74#endif // ICU PATCH: close #if !UCONFIG_NO_FORMATTING