001/** 002 * The MIT License (MIT) 003 * 004 * Copyright (c) 2015-2016 decimal4j (tools4j), Marco Terzer 005 * 006 * Permission is hereby granted, free of charge, to any person obtaining a copy 007 * of this software and associated documentation files (the "Software"), to deal 008 * in the Software without restriction, including without limitation the rights 009 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 010 * copies of the Software, and to permit persons to whom the Software is 011 * furnished to do so, subject to the following conditions: 012 * 013 * The above copyright notice and this permission notice shall be included in all 014 * copies or substantial portions of the Software. 015 * 016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 019 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 022 * SOFTWARE. 023 */ 024package org.decimal4j.exact; 025 026import java.util.Objects; 027 028import org.decimal4j.api.Decimal; 029import org.decimal4j.immutable.Decimal0f; 030import org.decimal4j.immutable.Decimal1f; 031import org.decimal4j.immutable.Decimal2f; 032import org.decimal4j.immutable.Decimal3f; 033import org.decimal4j.immutable.Decimal4f; 034import org.decimal4j.immutable.Decimal5f; 035import org.decimal4j.immutable.Decimal6f; 036import org.decimal4j.immutable.Decimal7f; 037import org.decimal4j.immutable.Decimal8f; 038import org.decimal4j.immutable.Decimal9f; 039import org.decimal4j.immutable.Decimal10f; 040import org.decimal4j.immutable.Decimal11f; 041import org.decimal4j.immutable.Decimal12f; 042import org.decimal4j.immutable.Decimal13f; 043import org.decimal4j.immutable.Decimal14f; 044import org.decimal4j.immutable.Decimal15f; 045import org.decimal4j.immutable.Decimal16f; 046import org.decimal4j.immutable.Decimal17f; 047import org.decimal4j.immutable.Decimal18f; 048import org.decimal4j.mutable.MutableDecimal0f; 049import org.decimal4j.mutable.MutableDecimal1f; 050import org.decimal4j.mutable.MutableDecimal2f; 051import org.decimal4j.mutable.MutableDecimal4f; 052import org.decimal4j.mutable.MutableDecimal5f; 053import org.decimal4j.mutable.MutableDecimal6f; 054import org.decimal4j.mutable.MutableDecimal7f; 055import org.decimal4j.mutable.MutableDecimal8f; 056import org.decimal4j.mutable.MutableDecimal9f; 057import org.decimal4j.mutable.MutableDecimal10f; 058import org.decimal4j.mutable.MutableDecimal11f; 059import org.decimal4j.mutable.MutableDecimal12f; 060import org.decimal4j.mutable.MutableDecimal13f; 061import org.decimal4j.mutable.MutableDecimal14f; 062import org.decimal4j.mutable.MutableDecimal15f; 063import org.decimal4j.scale.Scale3f; 064 065/** 066 * A {@code Multipliable3f} encapsulates a Decimal of scale 3 and facilitates 067 * exact typed multiplication. The multipliable object acts as first factor in the multiplication 068 * and provides a set of overloaded methods for different scales. Each one of those methods 069 * delivers a different result scale which represents the appropriate scale for the product of 070 * an exact multiplication. 071 * <p> 072 * A {@code Multipliable3f} object is returned by {@link Decimal3f#multiplyExact()}, 073 * hence an exact typed multiplication can be written as: 074 * <pre> 075 * Decimal3f value = ... //some value 076 * Decimal5f product = value.multiplyExact().by(Decimal2f.FIVE); 077 * </pre> 078 */ 079public final class Multipliable3f { 080 081 private final Decimal<Scale3f> value; 082 083 /** 084 * Constructor with Decimal value to be encapsulated. 085 * @param value the decimal value to be wrapped as a multipliable object 086 */ 087 public Multipliable3f(Decimal<Scale3f> value) { 088 this.value = Objects.requireNonNull(value, "value cannot be null"); 089 } 090 091 /** 092 * Returns the value underlying this Multipliable3f. 093 * @return the Decimal value wrapped by this multipliable object 094 */ 095 public Decimal<Scale3f> getValue() { 096 return value; 097 } 098 099 /** 100 * Returns a {@code Decimal} whose value is <tt>(this<sup>2</sup>)</tt>. The 101 * result is exact and has scale 6 which is twice the scale of 102 * the Decimal that this multipliable object represents. An 103 * {@link ArithmeticException} is thrown if the product is out of the 104 * possible range for a {@code Decimal6f}. 105 * <p> 106 * Note that the result is <i>always</i> a new instance. 107 * 108 * @return <tt>(this * this)</tt> 109 * @throws ArithmeticException 110 * if an overflow occurs and product is out of the possible 111 * range for a {@code Decimal6f} 112 */ 113 public Decimal6f square() { 114 return by(this.value); 115 } 116 117 /** 118 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 119 * result is exact and has scale 6 which is the sum of the scales 120 * of the Decimal that this multipliable object represents and the scale of 121 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 122 * product is out of the possible range for a {@code Decimal6f}. 123 * <p> 124 * Note that the result is <i>always</i> a new instance. 125 * 126 * @param factor 127 * the factor to multiply with the Decimal that this multipliable represents 128 * @return <tt>(this * factor)</tt> 129 * @throws ArithmeticException 130 * if an overflow occurs and product is out of the possible 131 * range for a {@code Decimal6f} 132 */ 133 public Decimal6f by(Decimal<Scale3f> factor) { 134 return Decimal6f.valueOf(this.value.multiplyExact(factor)); 135 } 136 137 /** 138 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 139 * result is exact and has scale 3 which is the sum of the scales 140 * of the Decimal that this multipliable object represents and the scale of 141 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 142 * product is out of the possible range for a {@code Decimal3f}. 143 * <p> 144 * Note that the result is <i>always</i> a new instance. 145 * 146 * @param factor 147 * the factor to multiply with the Decimal that this multipliable represents 148 * @return <tt>(this * factor)</tt> 149 * @throws ArithmeticException 150 * if an overflow occurs and product is out of the possible 151 * range for a {@code Decimal3f} 152 */ 153 public Decimal3f by(Decimal0f factor) { 154 return Decimal3f.valueOf(this.value.multiplyExact(factor)); 155 } 156 /** 157 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 158 * result is exact and has scale 3 which is the sum of the scales 159 * of the Decimal that this multipliable object represents and the scale of 160 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 161 * product is out of the possible range for a {@code Decimal3f}. 162 * <p> 163 * Note that the result is <i>always</i> a new instance. 164 * 165 * @param factor 166 * the factor to multiply with the Decimal that this multipliable represents 167 * @return <tt>(this * factor)</tt> 168 * @throws ArithmeticException 169 * if an overflow occurs and product is out of the possible 170 * range for a {@code Decimal3f} 171 */ 172 public Decimal3f by(MutableDecimal0f factor) { 173 return Decimal3f.valueOf(this.value.multiplyExact(factor)); 174 } 175 176 /** 177 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 178 * result is exact and has scale 4 which is the sum of the scales 179 * of the Decimal that this multipliable object represents and the scale of 180 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 181 * product is out of the possible range for a {@code Decimal4f}. 182 * <p> 183 * Note that the result is <i>always</i> a new instance. 184 * 185 * @param factor 186 * the factor to multiply with the Decimal that this multipliable represents 187 * @return <tt>(this * factor)</tt> 188 * @throws ArithmeticException 189 * if an overflow occurs and product is out of the possible 190 * range for a {@code Decimal4f} 191 */ 192 public Decimal4f by(Decimal1f factor) { 193 return Decimal4f.valueOf(this.value.multiplyExact(factor)); 194 } 195 /** 196 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 197 * result is exact and has scale 4 which is the sum of the scales 198 * of the Decimal that this multipliable object represents and the scale of 199 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 200 * product is out of the possible range for a {@code Decimal4f}. 201 * <p> 202 * Note that the result is <i>always</i> a new instance. 203 * 204 * @param factor 205 * the factor to multiply with the Decimal that this multipliable represents 206 * @return <tt>(this * factor)</tt> 207 * @throws ArithmeticException 208 * if an overflow occurs and product is out of the possible 209 * range for a {@code Decimal4f} 210 */ 211 public Decimal4f by(MutableDecimal1f factor) { 212 return Decimal4f.valueOf(this.value.multiplyExact(factor)); 213 } 214 215 /** 216 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 217 * result is exact and has scale 5 which is the sum of the scales 218 * of the Decimal that this multipliable object represents and the scale of 219 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 220 * product is out of the possible range for a {@code Decimal5f}. 221 * <p> 222 * Note that the result is <i>always</i> a new instance. 223 * 224 * @param factor 225 * the factor to multiply with the Decimal that this multipliable represents 226 * @return <tt>(this * factor)</tt> 227 * @throws ArithmeticException 228 * if an overflow occurs and product is out of the possible 229 * range for a {@code Decimal5f} 230 */ 231 public Decimal5f by(Decimal2f factor) { 232 return Decimal5f.valueOf(this.value.multiplyExact(factor)); 233 } 234 /** 235 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 236 * result is exact and has scale 5 which is the sum of the scales 237 * of the Decimal that this multipliable object represents and the scale of 238 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 239 * product is out of the possible range for a {@code Decimal5f}. 240 * <p> 241 * Note that the result is <i>always</i> a new instance. 242 * 243 * @param factor 244 * the factor to multiply with the Decimal that this multipliable represents 245 * @return <tt>(this * factor)</tt> 246 * @throws ArithmeticException 247 * if an overflow occurs and product is out of the possible 248 * range for a {@code Decimal5f} 249 */ 250 public Decimal5f by(MutableDecimal2f factor) { 251 return Decimal5f.valueOf(this.value.multiplyExact(factor)); 252 } 253 254 /** 255 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 256 * result is exact and has scale 7 which is the sum of the scales 257 * of the Decimal that this multipliable object represents and the scale of 258 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 259 * product is out of the possible range for a {@code Decimal7f}. 260 * <p> 261 * Note that the result is <i>always</i> a new instance. 262 * 263 * @param factor 264 * the factor to multiply with the Decimal that this multipliable represents 265 * @return <tt>(this * factor)</tt> 266 * @throws ArithmeticException 267 * if an overflow occurs and product is out of the possible 268 * range for a {@code Decimal7f} 269 */ 270 public Decimal7f by(Decimal4f factor) { 271 return Decimal7f.valueOf(this.value.multiplyExact(factor)); 272 } 273 /** 274 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 275 * result is exact and has scale 7 which is the sum of the scales 276 * of the Decimal that this multipliable object represents and the scale of 277 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 278 * product is out of the possible range for a {@code Decimal7f}. 279 * <p> 280 * Note that the result is <i>always</i> a new instance. 281 * 282 * @param factor 283 * the factor to multiply with the Decimal that this multipliable represents 284 * @return <tt>(this * factor)</tt> 285 * @throws ArithmeticException 286 * if an overflow occurs and product is out of the possible 287 * range for a {@code Decimal7f} 288 */ 289 public Decimal7f by(MutableDecimal4f factor) { 290 return Decimal7f.valueOf(this.value.multiplyExact(factor)); 291 } 292 293 /** 294 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 295 * result is exact and has scale 8 which is the sum of the scales 296 * of the Decimal that this multipliable object represents and the scale of 297 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 298 * product is out of the possible range for a {@code Decimal8f}. 299 * <p> 300 * Note that the result is <i>always</i> a new instance. 301 * 302 * @param factor 303 * the factor to multiply with the Decimal that this multipliable represents 304 * @return <tt>(this * factor)</tt> 305 * @throws ArithmeticException 306 * if an overflow occurs and product is out of the possible 307 * range for a {@code Decimal8f} 308 */ 309 public Decimal8f by(Decimal5f factor) { 310 return Decimal8f.valueOf(this.value.multiplyExact(factor)); 311 } 312 /** 313 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 314 * result is exact and has scale 8 which is the sum of the scales 315 * of the Decimal that this multipliable object represents and the scale of 316 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 317 * product is out of the possible range for a {@code Decimal8f}. 318 * <p> 319 * Note that the result is <i>always</i> a new instance. 320 * 321 * @param factor 322 * the factor to multiply with the Decimal that this multipliable represents 323 * @return <tt>(this * factor)</tt> 324 * @throws ArithmeticException 325 * if an overflow occurs and product is out of the possible 326 * range for a {@code Decimal8f} 327 */ 328 public Decimal8f by(MutableDecimal5f factor) { 329 return Decimal8f.valueOf(this.value.multiplyExact(factor)); 330 } 331 332 /** 333 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 334 * result is exact and has scale 9 which is the sum of the scales 335 * of the Decimal that this multipliable object represents and the scale of 336 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 337 * product is out of the possible range for a {@code Decimal9f}. 338 * <p> 339 * Note that the result is <i>always</i> a new instance. 340 * 341 * @param factor 342 * the factor to multiply with the Decimal that this multipliable represents 343 * @return <tt>(this * factor)</tt> 344 * @throws ArithmeticException 345 * if an overflow occurs and product is out of the possible 346 * range for a {@code Decimal9f} 347 */ 348 public Decimal9f by(Decimal6f factor) { 349 return Decimal9f.valueOf(this.value.multiplyExact(factor)); 350 } 351 /** 352 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 353 * result is exact and has scale 9 which is the sum of the scales 354 * of the Decimal that this multipliable object represents and the scale of 355 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 356 * product is out of the possible range for a {@code Decimal9f}. 357 * <p> 358 * Note that the result is <i>always</i> a new instance. 359 * 360 * @param factor 361 * the factor to multiply with the Decimal that this multipliable represents 362 * @return <tt>(this * factor)</tt> 363 * @throws ArithmeticException 364 * if an overflow occurs and product is out of the possible 365 * range for a {@code Decimal9f} 366 */ 367 public Decimal9f by(MutableDecimal6f factor) { 368 return Decimal9f.valueOf(this.value.multiplyExact(factor)); 369 } 370 371 /** 372 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 373 * result is exact and has scale 10 which is the sum of the scales 374 * of the Decimal that this multipliable object represents and the scale of 375 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 376 * product is out of the possible range for a {@code Decimal10f}. 377 * <p> 378 * Note that the result is <i>always</i> a new instance. 379 * 380 * @param factor 381 * the factor to multiply with the Decimal that this multipliable represents 382 * @return <tt>(this * factor)</tt> 383 * @throws ArithmeticException 384 * if an overflow occurs and product is out of the possible 385 * range for a {@code Decimal10f} 386 */ 387 public Decimal10f by(Decimal7f factor) { 388 return Decimal10f.valueOf(this.value.multiplyExact(factor)); 389 } 390 /** 391 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 392 * result is exact and has scale 10 which is the sum of the scales 393 * of the Decimal that this multipliable object represents and the scale of 394 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 395 * product is out of the possible range for a {@code Decimal10f}. 396 * <p> 397 * Note that the result is <i>always</i> a new instance. 398 * 399 * @param factor 400 * the factor to multiply with the Decimal that this multipliable represents 401 * @return <tt>(this * factor)</tt> 402 * @throws ArithmeticException 403 * if an overflow occurs and product is out of the possible 404 * range for a {@code Decimal10f} 405 */ 406 public Decimal10f by(MutableDecimal7f factor) { 407 return Decimal10f.valueOf(this.value.multiplyExact(factor)); 408 } 409 410 /** 411 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 412 * result is exact and has scale 11 which is the sum of the scales 413 * of the Decimal that this multipliable object represents and the scale of 414 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 415 * product is out of the possible range for a {@code Decimal11f}. 416 * <p> 417 * Note that the result is <i>always</i> a new instance. 418 * 419 * @param factor 420 * the factor to multiply with the Decimal that this multipliable represents 421 * @return <tt>(this * factor)</tt> 422 * @throws ArithmeticException 423 * if an overflow occurs and product is out of the possible 424 * range for a {@code Decimal11f} 425 */ 426 public Decimal11f by(Decimal8f factor) { 427 return Decimal11f.valueOf(this.value.multiplyExact(factor)); 428 } 429 /** 430 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 431 * result is exact and has scale 11 which is the sum of the scales 432 * of the Decimal that this multipliable object represents and the scale of 433 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 434 * product is out of the possible range for a {@code Decimal11f}. 435 * <p> 436 * Note that the result is <i>always</i> a new instance. 437 * 438 * @param factor 439 * the factor to multiply with the Decimal that this multipliable represents 440 * @return <tt>(this * factor)</tt> 441 * @throws ArithmeticException 442 * if an overflow occurs and product is out of the possible 443 * range for a {@code Decimal11f} 444 */ 445 public Decimal11f by(MutableDecimal8f factor) { 446 return Decimal11f.valueOf(this.value.multiplyExact(factor)); 447 } 448 449 /** 450 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 451 * result is exact and has scale 12 which is the sum of the scales 452 * of the Decimal that this multipliable object represents and the scale of 453 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 454 * product is out of the possible range for a {@code Decimal12f}. 455 * <p> 456 * Note that the result is <i>always</i> a new instance. 457 * 458 * @param factor 459 * the factor to multiply with the Decimal that this multipliable represents 460 * @return <tt>(this * factor)</tt> 461 * @throws ArithmeticException 462 * if an overflow occurs and product is out of the possible 463 * range for a {@code Decimal12f} 464 */ 465 public Decimal12f by(Decimal9f factor) { 466 return Decimal12f.valueOf(this.value.multiplyExact(factor)); 467 } 468 /** 469 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 470 * result is exact and has scale 12 which is the sum of the scales 471 * of the Decimal that this multipliable object represents and the scale of 472 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 473 * product is out of the possible range for a {@code Decimal12f}. 474 * <p> 475 * Note that the result is <i>always</i> a new instance. 476 * 477 * @param factor 478 * the factor to multiply with the Decimal that this multipliable represents 479 * @return <tt>(this * factor)</tt> 480 * @throws ArithmeticException 481 * if an overflow occurs and product is out of the possible 482 * range for a {@code Decimal12f} 483 */ 484 public Decimal12f by(MutableDecimal9f factor) { 485 return Decimal12f.valueOf(this.value.multiplyExact(factor)); 486 } 487 488 /** 489 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 490 * result is exact and has scale 13 which is the sum of the scales 491 * of the Decimal that this multipliable object represents and the scale of 492 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 493 * product is out of the possible range for a {@code Decimal13f}. 494 * <p> 495 * Note that the result is <i>always</i> a new instance. 496 * 497 * @param factor 498 * the factor to multiply with the Decimal that this multipliable represents 499 * @return <tt>(this * factor)</tt> 500 * @throws ArithmeticException 501 * if an overflow occurs and product is out of the possible 502 * range for a {@code Decimal13f} 503 */ 504 public Decimal13f by(Decimal10f factor) { 505 return Decimal13f.valueOf(this.value.multiplyExact(factor)); 506 } 507 /** 508 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 509 * result is exact and has scale 13 which is the sum of the scales 510 * of the Decimal that this multipliable object represents and the scale of 511 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 512 * product is out of the possible range for a {@code Decimal13f}. 513 * <p> 514 * Note that the result is <i>always</i> a new instance. 515 * 516 * @param factor 517 * the factor to multiply with the Decimal that this multipliable represents 518 * @return <tt>(this * factor)</tt> 519 * @throws ArithmeticException 520 * if an overflow occurs and product is out of the possible 521 * range for a {@code Decimal13f} 522 */ 523 public Decimal13f by(MutableDecimal10f factor) { 524 return Decimal13f.valueOf(this.value.multiplyExact(factor)); 525 } 526 527 /** 528 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 529 * result is exact and has scale 14 which is the sum of the scales 530 * of the Decimal that this multipliable object represents and the scale of 531 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 532 * product is out of the possible range for a {@code Decimal14f}. 533 * <p> 534 * Note that the result is <i>always</i> a new instance. 535 * 536 * @param factor 537 * the factor to multiply with the Decimal that this multipliable represents 538 * @return <tt>(this * factor)</tt> 539 * @throws ArithmeticException 540 * if an overflow occurs and product is out of the possible 541 * range for a {@code Decimal14f} 542 */ 543 public Decimal14f by(Decimal11f factor) { 544 return Decimal14f.valueOf(this.value.multiplyExact(factor)); 545 } 546 /** 547 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 548 * result is exact and has scale 14 which is the sum of the scales 549 * of the Decimal that this multipliable object represents and the scale of 550 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 551 * product is out of the possible range for a {@code Decimal14f}. 552 * <p> 553 * Note that the result is <i>always</i> a new instance. 554 * 555 * @param factor 556 * the factor to multiply with the Decimal that this multipliable represents 557 * @return <tt>(this * factor)</tt> 558 * @throws ArithmeticException 559 * if an overflow occurs and product is out of the possible 560 * range for a {@code Decimal14f} 561 */ 562 public Decimal14f by(MutableDecimal11f factor) { 563 return Decimal14f.valueOf(this.value.multiplyExact(factor)); 564 } 565 566 /** 567 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 568 * result is exact and has scale 15 which is the sum of the scales 569 * of the Decimal that this multipliable object represents and the scale of 570 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 571 * product is out of the possible range for a {@code Decimal15f}. 572 * <p> 573 * Note that the result is <i>always</i> a new instance. 574 * 575 * @param factor 576 * the factor to multiply with the Decimal that this multipliable represents 577 * @return <tt>(this * factor)</tt> 578 * @throws ArithmeticException 579 * if an overflow occurs and product is out of the possible 580 * range for a {@code Decimal15f} 581 */ 582 public Decimal15f by(Decimal12f factor) { 583 return Decimal15f.valueOf(this.value.multiplyExact(factor)); 584 } 585 /** 586 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 587 * result is exact and has scale 15 which is the sum of the scales 588 * of the Decimal that this multipliable object represents and the scale of 589 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 590 * product is out of the possible range for a {@code Decimal15f}. 591 * <p> 592 * Note that the result is <i>always</i> a new instance. 593 * 594 * @param factor 595 * the factor to multiply with the Decimal that this multipliable represents 596 * @return <tt>(this * factor)</tt> 597 * @throws ArithmeticException 598 * if an overflow occurs and product is out of the possible 599 * range for a {@code Decimal15f} 600 */ 601 public Decimal15f by(MutableDecimal12f factor) { 602 return Decimal15f.valueOf(this.value.multiplyExact(factor)); 603 } 604 605 /** 606 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 607 * result is exact and has scale 16 which is the sum of the scales 608 * of the Decimal that this multipliable object represents and the scale of 609 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 610 * product is out of the possible range for a {@code Decimal16f}. 611 * <p> 612 * Note that the result is <i>always</i> a new instance. 613 * 614 * @param factor 615 * the factor to multiply with the Decimal that this multipliable represents 616 * @return <tt>(this * factor)</tt> 617 * @throws ArithmeticException 618 * if an overflow occurs and product is out of the possible 619 * range for a {@code Decimal16f} 620 */ 621 public Decimal16f by(Decimal13f factor) { 622 return Decimal16f.valueOf(this.value.multiplyExact(factor)); 623 } 624 /** 625 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 626 * result is exact and has scale 16 which is the sum of the scales 627 * of the Decimal that this multipliable object represents and the scale of 628 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 629 * product is out of the possible range for a {@code Decimal16f}. 630 * <p> 631 * Note that the result is <i>always</i> a new instance. 632 * 633 * @param factor 634 * the factor to multiply with the Decimal that this multipliable represents 635 * @return <tt>(this * factor)</tt> 636 * @throws ArithmeticException 637 * if an overflow occurs and product is out of the possible 638 * range for a {@code Decimal16f} 639 */ 640 public Decimal16f by(MutableDecimal13f factor) { 641 return Decimal16f.valueOf(this.value.multiplyExact(factor)); 642 } 643 644 /** 645 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 646 * result is exact and has scale 17 which is the sum of the scales 647 * of the Decimal that this multipliable object represents and the scale of 648 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 649 * product is out of the possible range for a {@code Decimal17f}. 650 * <p> 651 * Note that the result is <i>always</i> a new instance. 652 * 653 * @param factor 654 * the factor to multiply with the Decimal that this multipliable represents 655 * @return <tt>(this * factor)</tt> 656 * @throws ArithmeticException 657 * if an overflow occurs and product is out of the possible 658 * range for a {@code Decimal17f} 659 */ 660 public Decimal17f by(Decimal14f factor) { 661 return Decimal17f.valueOf(this.value.multiplyExact(factor)); 662 } 663 /** 664 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 665 * result is exact and has scale 17 which is the sum of the scales 666 * of the Decimal that this multipliable object represents and the scale of 667 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 668 * product is out of the possible range for a {@code Decimal17f}. 669 * <p> 670 * Note that the result is <i>always</i> a new instance. 671 * 672 * @param factor 673 * the factor to multiply with the Decimal that this multipliable represents 674 * @return <tt>(this * factor)</tt> 675 * @throws ArithmeticException 676 * if an overflow occurs and product is out of the possible 677 * range for a {@code Decimal17f} 678 */ 679 public Decimal17f by(MutableDecimal14f factor) { 680 return Decimal17f.valueOf(this.value.multiplyExact(factor)); 681 } 682 683 /** 684 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 685 * result is exact and has scale 18 which is the sum of the scales 686 * of the Decimal that this multipliable object represents and the scale of 687 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 688 * product is out of the possible range for a {@code Decimal18f}. 689 * <p> 690 * Note that the result is <i>always</i> a new instance. 691 * 692 * @param factor 693 * the factor to multiply with the Decimal that this multipliable represents 694 * @return <tt>(this * factor)</tt> 695 * @throws ArithmeticException 696 * if an overflow occurs and product is out of the possible 697 * range for a {@code Decimal18f} 698 */ 699 public Decimal18f by(Decimal15f factor) { 700 return Decimal18f.valueOf(this.value.multiplyExact(factor)); 701 } 702 /** 703 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 704 * result is exact and has scale 18 which is the sum of the scales 705 * of the Decimal that this multipliable object represents and the scale of 706 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 707 * product is out of the possible range for a {@code Decimal18f}. 708 * <p> 709 * Note that the result is <i>always</i> a new instance. 710 * 711 * @param factor 712 * the factor to multiply with the Decimal that this multipliable represents 713 * @return <tt>(this * factor)</tt> 714 * @throws ArithmeticException 715 * if an overflow occurs and product is out of the possible 716 * range for a {@code Decimal18f} 717 */ 718 public Decimal18f by(MutableDecimal15f factor) { 719 return Decimal18f.valueOf(this.value.multiplyExact(factor)); 720 } 721 722 723 /** 724 * Returns a hash code for this <tt>Multipliable3f</tt> which happens to be the 725 * hash code of the underlying {@code Decimal3f} value. 726 * 727 * @return a hash code value for this object 728 * @see Decimal#hashCode() 729 */ 730 @Override 731 public int hashCode() { 732 return value.hashCode(); 733 } 734 735 /** 736 * Compares this Multipliable3f to the specified object. The result is {@code true} 737 * if and only if the argument is a {@code Multipliable3f} with an equal underlying 738 * {@link #getValue() value}. 739 * 740 * @param obj 741 * the object to compare with 742 * @return {@code true} if the argument is a {@code Multipliable3f} and if its value 743 * is equal to this multipliables's value; {@code false} otherwise 744 * @see #getValue() 745 * @see Decimal#equals(Object) 746 */ 747 @Override 748 public boolean equals(Object obj) { 749 if (this == obj) return true; 750 if (obj == null) return false; 751 if (getClass() != obj.getClass()) return false; 752 return value.equals(((Multipliable3f)obj).value); 753 } 754 755 /** 756 * Returns a string representation of this {@code Multipliable3f} which is 757 * simply the string representation of the underlying Decimal {@link #getValue() value}. 758 * 759 * @return a {@code String} Decimal representation of this {@code Multipliable3f}'s 760 * value with all the fraction digits (including trailing zeros) 761 * @see #getValue() 762 * @see Decimal#toString() 763 */ 764 @Override 765 public String toString() { 766 return value.toString(); 767 } 768}