github.com/richardwilkes/toolbox@v1.121.0/xmath/fixed/config.go (about) 1 // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved. 2 // 3 // This Source Code Form is subject to the terms of the Mozilla Public 4 // License, version 2.0. If a copy of the MPL was not distributed with 5 // this file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 // 7 // This Source Code Form is "Incompatible With Secondary Licenses", as 8 // defined by the Mozilla Public License, version 2.0. 9 10 package fixed 11 12 // Dx is the constraint for allowed decimal place types. These methods must return a static value and be usable with the 13 // zero value of the type. 14 type Dx interface { 15 Places() int 16 Multiplier() int64 17 } 18 19 // D1 is used for fixed-point types with 1 decimal place. 20 type D1 int64 21 22 // Places implements Dx. 23 func (d D1) Places() int { 24 return 1 25 } 26 27 // Multiplier implements Dx. 28 func (d D1) Multiplier() int64 { 29 return 10 30 } 31 32 // D2 is used for fixed-point types with 2 decimal places. 33 type D2 int64 34 35 // Places implements Dx. 36 func (d D2) Places() int { 37 return 2 38 } 39 40 // Multiplier implements Dx. 41 func (d D2) Multiplier() int64 { 42 return 100 43 } 44 45 // D3 is used for fixed-point types with 3 decimal places. 46 type D3 int64 47 48 // Places implements Dx. 49 func (d D3) Places() int { 50 return 3 51 } 52 53 // Multiplier implements Dx. 54 func (d D3) Multiplier() int64 { 55 return 1_000 56 } 57 58 // D4 is used for fixed-point types with 4 decimal places. 59 type D4 int64 60 61 // Places implements Dx. 62 func (d D4) Places() int { 63 return 4 64 } 65 66 // Multiplier implements Dx. 67 func (d D4) Multiplier() int64 { 68 return 10_000 69 } 70 71 // D5 is used for fixed-point types with 5 decimal places. 72 type D5 int64 73 74 // Places implements Dx. 75 func (d D5) Places() int { 76 return 5 77 } 78 79 // Multiplier implements Dx. 80 func (d D5) Multiplier() int64 { 81 return 100_000 82 } 83 84 // D6 is used for fixed-point types with 6 decimal places. 85 type D6 int64 86 87 // Places implements Dx. 88 func (d D6) Places() int { 89 return 6 90 } 91 92 // Multiplier implements Dx. 93 func (d D6) Multiplier() int64 { 94 return 1_000_000 95 } 96 97 // D7 is used for fixed-point types with 7 decimal places. 98 type D7 int64 99 100 // Places implements Dx. 101 func (d D7) Places() int { 102 return 7 103 } 104 105 // Multiplier implements Dx. 106 func (d D7) Multiplier() int64 { 107 return 10_000_000 108 } 109 110 // D8 is used for fixed-point types with 8 decimal places. 111 type D8 int64 112 113 // Places implements Dx. 114 func (d D8) Places() int { 115 return 8 116 } 117 118 // Multiplier implements Dx. 119 func (d D8) Multiplier() int64 { 120 return 100_000_000 121 } 122 123 // D9 is used for fixed-point types with 9 decimal places. 124 type D9 int64 125 126 // Places implements Dx. 127 func (d D9) Places() int { 128 return 9 129 } 130 131 // Multiplier implements Dx. 132 func (d D9) Multiplier() int64 { 133 return 1_000_000_000 134 } 135 136 // D10 is used for fixed-point types with 10 decimal places. 137 type D10 int64 138 139 // Places implements Dx. 140 func (d D10) Places() int { 141 return 10 142 } 143 144 // Multiplier implements Dx. 145 func (d D10) Multiplier() int64 { 146 return 10_000_000_000 147 } 148 149 // D11 is used for fixed-point types with 11 decimal places. 150 type D11 int64 151 152 // Places implements Dx. 153 func (d D11) Places() int { 154 return 11 155 } 156 157 // Multiplier implements Dx. 158 func (d D11) Multiplier() int64 { 159 return 100_000_000_000 160 } 161 162 // D12 is used for fixed-point types with 12 decimal places. 163 type D12 int64 164 165 // Places implements Dx. 166 func (d D12) Places() int { 167 return 12 168 } 169 170 // Multiplier implements Dx. 171 func (d D12) Multiplier() int64 { 172 return 1_000_000_000_000 173 } 174 175 // D13 is used for fixed-point types with 13 decimal places. 176 type D13 int64 177 178 // Places implements Dx. 179 func (d D13) Places() int { 180 return 13 181 } 182 183 // Multiplier implements Dx. 184 func (d D13) Multiplier() int64 { 185 return 10_000_000_000_000 186 } 187 188 // D14 is used for fixed-point types with 14 decimal places. 189 type D14 int64 190 191 // Places implements Dx. 192 func (d D14) Places() int { 193 return 14 194 } 195 196 // Multiplier implements Dx. 197 func (d D14) Multiplier() int64 { 198 return 100_000_000_000_000 199 } 200 201 // D15 is used for fixed-point types with 15 decimal places. 202 type D15 int64 203 204 // Places implements Dx. 205 func (d D15) Places() int { 206 return 15 207 } 208 209 // Multiplier implements Dx. 210 func (d D15) Multiplier() int64 { 211 return 1_000_000_000_000_000 212 } 213 214 // D16 is used for fixed-point types with 16 decimal places. 215 type D16 int64 216 217 // Places implements Dx. 218 func (d D16) Places() int { 219 return 16 220 } 221 222 // Multiplier implements Dx. 223 func (d D16) Multiplier() int64 { 224 return 10_000_000_000_000_000 225 }