| 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 |
declare (strict_types=1); |
| 29 |
namespace Dudlewebs\WPMCS\Ramsey\Uuid\Math; |
| 30 |
|
| 31 |
/** |
| 32 |
* Specifies a rounding behavior for numerical operations capable of discarding |
| 33 |
* precision. |
| 34 |
* |
| 35 |
* Each rounding mode indicates how the least significant returned digit of a |
| 36 |
* rounded result is to be calculated. If fewer digits are returned than the |
| 37 |
* digits needed to represent the exact numerical result, the discarded digits |
| 38 |
* will be referred to as the discarded fraction regardless the digits' |
| 39 |
* contribution to the value of the number. In other words, considered as a |
| 40 |
* numerical value, the discarded fraction could have an absolute value greater |
| 41 |
* than one. |
| 42 |
*/ |
| 43 |
final class RoundingMode |
| 44 |
{ |
| 45 |
/** |
| 46 |
* Private constructor. This class is not instantiable. |
| 47 |
* |
| 48 |
* @codeCoverageIgnore |
| 49 |
*/ |
| 50 |
private function __construct() |
| 51 |
{ |
| 52 |
} |
| 53 |
/** |
| 54 |
* Asserts that the requested operation has an exact result, hence no |
| 55 |
* rounding is necessary. |
| 56 |
*/ |
| 57 |
public const UNNECESSARY = 0; |
| 58 |
/** |
| 59 |
* Rounds away from zero. |
| 60 |
* |
| 61 |
* Always increments the digit prior to a nonzero discarded fraction. |
| 62 |
* Note that this rounding mode never decreases the magnitude of the |
| 63 |
* calculated value. |
| 64 |
*/ |
| 65 |
public const UP = 1; |
| 66 |
/** |
| 67 |
* Rounds towards zero. |
| 68 |
* |
| 69 |
* Never increments the digit prior to a discarded fraction (i.e., |
| 70 |
* truncates). Note that this rounding mode never increases the magnitude of |
| 71 |
* the calculated value. |
| 72 |
*/ |
| 73 |
public const DOWN = 2; |
| 74 |
/** |
| 75 |
* Rounds towards positive infinity. |
| 76 |
* |
| 77 |
* If the result is positive, behaves as for UP; if negative, behaves as for |
| 78 |
* DOWN. Note that this rounding mode never decreases the calculated value. |
| 79 |
*/ |
| 80 |
public const CEILING = 3; |
| 81 |
/** |
| 82 |
* Rounds towards negative infinity. |
| 83 |
* |
| 84 |
* If the result is positive, behave as for DOWN; if negative, behave as for |
| 85 |
* UP. Note that this rounding mode never increases the calculated value. |
| 86 |
*/ |
| 87 |
public const FLOOR = 4; |
| 88 |
/** |
| 89 |
* Rounds towards "nearest neighbor" unless both neighbors are equidistant, |
| 90 |
* in which case round up. |
| 91 |
* |
| 92 |
* Behaves as for UP if the discarded fraction is >= 0.5; otherwise, behaves |
| 93 |
* as for DOWN. Note that this is the rounding mode commonly taught at |
| 94 |
* school. |
| 95 |
*/ |
| 96 |
public const HALF_UP = 5; |
| 97 |
/** |
| 98 |
* Rounds towards "nearest neighbor" unless both neighbors are equidistant, |
| 99 |
* in which case round down. |
| 100 |
* |
| 101 |
* Behaves as for UP if the discarded fraction is > 0.5; otherwise, behaves |
| 102 |
* as for DOWN. |
| 103 |
*/ |
| 104 |
public const HALF_DOWN = 6; |
| 105 |
/** |
| 106 |
* Rounds towards "nearest neighbor" unless both neighbors are equidistant, |
| 107 |
* in which case round towards positive infinity. |
| 108 |
* |
| 109 |
* If the result is positive, behaves as for HALF_UP; if negative, behaves |
| 110 |
* as for HALF_DOWN. |
| 111 |
*/ |
| 112 |
public const HALF_CEILING = 7; |
| 113 |
/** |
| 114 |
* Rounds towards "nearest neighbor" unless both neighbors are equidistant, |
| 115 |
* in which case round towards negative infinity. |
| 116 |
* |
| 117 |
* If the result is positive, behaves as for HALF_DOWN; if negative, behaves |
| 118 |
* as for HALF_UP. |
| 119 |
*/ |
| 120 |
public const HALF_FLOOR = 8; |
| 121 |
/** |
| 122 |
* Rounds towards the "nearest neighbor" unless both neighbors are |
| 123 |
* equidistant, in which case rounds towards the even neighbor. |
| 124 |
* |
| 125 |
* Behaves as for HALF_UP if the digit to the left of the discarded fraction |
| 126 |
* is odd; behaves as for HALF_DOWN if it's even. |
| 127 |
* |
| 128 |
* Note that this is the rounding mode that statistically minimizes |
| 129 |
* cumulative error when applied repeatedly over a sequence of calculations. |
| 130 |
* It is sometimes known as "Banker's rounding", and is chiefly used in the |
| 131 |
* USA. |
| 132 |
*/ |
| 133 |
public const HALF_EVEN = 9; |
| 134 |
} |
| 135 |
|