Debian Codegraph @

vendor/ramsey/uuid/src/Math/RoundingMode.php

raw
1 <?php
2
3 /**
4 * This file was originally part of brick/math
5 *
6 * Copyright (c) 2013-present Benjamin Morel
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 *
26 * @link https://github.com/brick/math brick/math at GitHub
27 */
28
29 declare(strict_types=1);
30
31 namespace Ramsey\Uuid\Math;
32
33 /**
34 * Specifies a rounding behavior for numerical operations capable of discarding precision.
35 *
36 * Each rounding mode indicates how the least significant returned digit of a rounded result is to be calculated. If
37 * fewer digits are returned than the digits needed to represent the exact numerical result, the discarded digits will
38 * be referred to as the discarded fraction regardless of the digits' contribution to the value of the number. In other
39 * words, considered as a numerical value, the discarded fraction could have an absolute value greater than one.
40 */
41 final class RoundingMode
42 {
43 /**
44 * Asserts that the requested operation has an exact result; hence no rounding is necessary.
45 */
46 public const UNNECESSARY = 0;
47
48 /**
49 * Rounds away from zero.
50 *
51 * Always increments the digit prior to a nonzero discarded fraction. Note that this rounding mode never decreases
52 * the magnitude of the calculated value.
53 */
54 public const UP = 1;
55
56 /**
57 * Rounds towards zero.
58 *
59 * Never increments the digit prior to a discarded fraction (i.e., truncates). Note that this rounding mode never
60 * increases the magnitude of the calculated value.
61 */
62 public const DOWN = 2;
63
64 /**
65 * Rounds towards positive infinity.
66 *
67 * If the result is positive, behaves as for UP; if negative, behaves as for DOWN. Note that this rounding mode
68 * never decreases the calculated value.
69 */
70 public const CEILING = 3;
71
72 /**
73 * Rounds towards negative infinity.
74 *
75 * If the result is positive, behave as for DOWN; if negative, behave as for UP. Note that this rounding mode never
76 * increases the calculated value.
77 */
78 public const FLOOR = 4;
79
80 /**
81 * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
82 *
83 * Behaves as for UP if the discarded fraction is >= 0.5; otherwise, behaves as for DOWN. Note that this is the
84 * rounding mode commonly taught at school.
85 */
86 public const HALF_UP = 5;
87
88 /**
89 * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
90 *
91 * Behaves as for UP if the discarded fraction is > 0.5; otherwise, behaves as for DOWN.
92 */
93 public const HALF_DOWN = 6;
94
95 /**
96 * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards positive infinity.
97 *
98 * If the result is positive, behaves as for HALF_UP; if negative, behaves as for HALF_DOWN.
99 */
100 public const HALF_CEILING = 7;
101
102 /**
103 * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards negative infinity.
104 *
105 * If the result is positive, behaves as for HALF_DOWN; if negative, behaves as for HALF_UP.
106 */
107 public const HALF_FLOOR = 8;
108
109 /**
110 * Rounds towards the "nearest neighbor" unless both neighbors are equidistant, in which case rounds towards the even neighbor.
111 *
112 * Behaves as for HALF_UP if the digit to the left of the discarded fraction is odd; behaves as for HALF_DOWN if it's even.
113 *
114 * Note that this is the rounding mode that statistically minimizes cumulative error when applied repeatedly over a
115 * sequence of calculations. It is sometimes known as "Banker's rounding", and is chiefly used in the USA.
116 */
117 public const HALF_EVEN = 9;
118
119 /**
120 * Private constructor. This class is not instantiable.
121 *
122 * @codeCoverageIgnore
123 */
124 private function __construct()
125 {
126 }
127 }