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.MutableDecimal1f; 049import org.decimal4j.mutable.MutableDecimal2f; 050import org.decimal4j.mutable.MutableDecimal3f; 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.mutable.MutableDecimal16f; 064import org.decimal4j.mutable.MutableDecimal17f; 065import org.decimal4j.mutable.MutableDecimal18f; 066import org.decimal4j.scale.Scale0f; 067 068/** 069 * A {@code Multipliable0f} encapsulates a Decimal of scale 0 and facilitates 070 * exact typed multiplication. The multipliable object acts as first factor in the multiplication 071 * and provides a set of overloaded methods for different scales. Each one of those methods 072 * delivers a different result scale which represents the appropriate scale for the product of 073 * an exact multiplication. 074 * <p> 075 * A {@code Multipliable0f} object is returned by {@link Decimal0f#multiplyExact()}, 076 * hence an exact typed multiplication can be written as: 077 * <pre> 078 * Decimal0f value = ... //some value 079 * Decimal2f product = value.multiplyExact().by(Decimal2f.FIVE); 080 * </pre> 081 */ 082public final class Multipliable0f { 083 084 private final Decimal<Scale0f> value; 085 086 /** 087 * Constructor with Decimal value to be encapsulated. 088 * @param value the decimal value to be wrapped as a multipliable object 089 */ 090 public Multipliable0f(Decimal<Scale0f> value) { 091 this.value = Objects.requireNonNull(value, "value cannot be null"); 092 } 093 094 /** 095 * Returns the value underlying this Multipliable0f. 096 * @return the Decimal value wrapped by this multipliable object 097 */ 098 public Decimal<Scale0f> getValue() { 099 return value; 100 } 101 102 /** 103 * Returns a {@code Decimal} whose value is <tt>(this<sup>2</sup>)</tt>. The 104 * result is exact and has scale 0 which is twice the scale of 105 * the Decimal that this multipliable object represents. An 106 * {@link ArithmeticException} is thrown if the product is out of the 107 * possible range for a {@code Decimal0f}. 108 * <p> 109 * Note that the result is <i>always</i> a new instance. 110 * 111 * @return <tt>(this * this)</tt> 112 * @throws ArithmeticException 113 * if an overflow occurs and product is out of the possible 114 * range for a {@code Decimal0f} 115 */ 116 public Decimal0f square() { 117 return by(this.value); 118 } 119 120 /** 121 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 122 * result is exact and has scale 0 which is the sum of the scales 123 * of the Decimal that this multipliable object represents and the scale of 124 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 125 * product is out of the possible range for a {@code Decimal0f}. 126 * <p> 127 * Note that the result is <i>always</i> a new instance. 128 * 129 * @param factor 130 * the factor to multiply with the Decimal that this multipliable represents 131 * @return <tt>(this * factor)</tt> 132 * @throws ArithmeticException 133 * if an overflow occurs and product is out of the possible 134 * range for a {@code Decimal0f} 135 */ 136 public Decimal0f by(Decimal<Scale0f> factor) { 137 return Decimal0f.valueOf(this.value.multiplyExact(factor)); 138 } 139 140 /** 141 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 142 * result is exact and has scale 1 which is the sum of the scales 143 * of the Decimal that this multipliable object represents and the scale of 144 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 145 * product is out of the possible range for a {@code Decimal1f}. 146 * <p> 147 * Note that the result is <i>always</i> a new instance. 148 * 149 * @param factor 150 * the factor to multiply with the Decimal that this multipliable represents 151 * @return <tt>(this * factor)</tt> 152 * @throws ArithmeticException 153 * if an overflow occurs and product is out of the possible 154 * range for a {@code Decimal1f} 155 */ 156 public Decimal1f by(Decimal1f factor) { 157 return Decimal1f.valueOf(this.value.multiplyExact(factor)); 158 } 159 /** 160 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 161 * result is exact and has scale 1 which is the sum of the scales 162 * of the Decimal that this multipliable object represents and the scale of 163 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 164 * product is out of the possible range for a {@code Decimal1f}. 165 * <p> 166 * Note that the result is <i>always</i> a new instance. 167 * 168 * @param factor 169 * the factor to multiply with the Decimal that this multipliable represents 170 * @return <tt>(this * factor)</tt> 171 * @throws ArithmeticException 172 * if an overflow occurs and product is out of the possible 173 * range for a {@code Decimal1f} 174 */ 175 public Decimal1f by(MutableDecimal1f factor) { 176 return Decimal1f.valueOf(this.value.multiplyExact(factor)); 177 } 178 179 /** 180 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 181 * result is exact and has scale 2 which is the sum of the scales 182 * of the Decimal that this multipliable object represents and the scale of 183 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 184 * product is out of the possible range for a {@code Decimal2f}. 185 * <p> 186 * Note that the result is <i>always</i> a new instance. 187 * 188 * @param factor 189 * the factor to multiply with the Decimal that this multipliable represents 190 * @return <tt>(this * factor)</tt> 191 * @throws ArithmeticException 192 * if an overflow occurs and product is out of the possible 193 * range for a {@code Decimal2f} 194 */ 195 public Decimal2f by(Decimal2f factor) { 196 return Decimal2f.valueOf(this.value.multiplyExact(factor)); 197 } 198 /** 199 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 200 * result is exact and has scale 2 which is the sum of the scales 201 * of the Decimal that this multipliable object represents and the scale of 202 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 203 * product is out of the possible range for a {@code Decimal2f}. 204 * <p> 205 * Note that the result is <i>always</i> a new instance. 206 * 207 * @param factor 208 * the factor to multiply with the Decimal that this multipliable represents 209 * @return <tt>(this * factor)</tt> 210 * @throws ArithmeticException 211 * if an overflow occurs and product is out of the possible 212 * range for a {@code Decimal2f} 213 */ 214 public Decimal2f by(MutableDecimal2f factor) { 215 return Decimal2f.valueOf(this.value.multiplyExact(factor)); 216 } 217 218 /** 219 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 220 * result is exact and has scale 3 which is the sum of the scales 221 * of the Decimal that this multipliable object represents and the scale of 222 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 223 * product is out of the possible range for a {@code Decimal3f}. 224 * <p> 225 * Note that the result is <i>always</i> a new instance. 226 * 227 * @param factor 228 * the factor to multiply with the Decimal that this multipliable represents 229 * @return <tt>(this * factor)</tt> 230 * @throws ArithmeticException 231 * if an overflow occurs and product is out of the possible 232 * range for a {@code Decimal3f} 233 */ 234 public Decimal3f by(Decimal3f factor) { 235 return Decimal3f.valueOf(this.value.multiplyExact(factor)); 236 } 237 /** 238 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 239 * result is exact and has scale 3 which is the sum of the scales 240 * of the Decimal that this multipliable object represents and the scale of 241 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 242 * product is out of the possible range for a {@code Decimal3f}. 243 * <p> 244 * Note that the result is <i>always</i> a new instance. 245 * 246 * @param factor 247 * the factor to multiply with the Decimal that this multipliable represents 248 * @return <tt>(this * factor)</tt> 249 * @throws ArithmeticException 250 * if an overflow occurs and product is out of the possible 251 * range for a {@code Decimal3f} 252 */ 253 public Decimal3f by(MutableDecimal3f factor) { 254 return Decimal3f.valueOf(this.value.multiplyExact(factor)); 255 } 256 257 /** 258 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 259 * result is exact and has scale 4 which is the sum of the scales 260 * of the Decimal that this multipliable object represents and the scale of 261 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 262 * product is out of the possible range for a {@code Decimal4f}. 263 * <p> 264 * Note that the result is <i>always</i> a new instance. 265 * 266 * @param factor 267 * the factor to multiply with the Decimal that this multipliable represents 268 * @return <tt>(this * factor)</tt> 269 * @throws ArithmeticException 270 * if an overflow occurs and product is out of the possible 271 * range for a {@code Decimal4f} 272 */ 273 public Decimal4f by(Decimal4f factor) { 274 return Decimal4f.valueOf(this.value.multiplyExact(factor)); 275 } 276 /** 277 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 278 * result is exact and has scale 4 which is the sum of the scales 279 * of the Decimal that this multipliable object represents and the scale of 280 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 281 * product is out of the possible range for a {@code Decimal4f}. 282 * <p> 283 * Note that the result is <i>always</i> a new instance. 284 * 285 * @param factor 286 * the factor to multiply with the Decimal that this multipliable represents 287 * @return <tt>(this * factor)</tt> 288 * @throws ArithmeticException 289 * if an overflow occurs and product is out of the possible 290 * range for a {@code Decimal4f} 291 */ 292 public Decimal4f by(MutableDecimal4f factor) { 293 return Decimal4f.valueOf(this.value.multiplyExact(factor)); 294 } 295 296 /** 297 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 298 * result is exact and has scale 5 which is the sum of the scales 299 * of the Decimal that this multipliable object represents and the scale of 300 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 301 * product is out of the possible range for a {@code Decimal5f}. 302 * <p> 303 * Note that the result is <i>always</i> a new instance. 304 * 305 * @param factor 306 * the factor to multiply with the Decimal that this multipliable represents 307 * @return <tt>(this * factor)</tt> 308 * @throws ArithmeticException 309 * if an overflow occurs and product is out of the possible 310 * range for a {@code Decimal5f} 311 */ 312 public Decimal5f by(Decimal5f factor) { 313 return Decimal5f.valueOf(this.value.multiplyExact(factor)); 314 } 315 /** 316 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 317 * result is exact and has scale 5 which is the sum of the scales 318 * of the Decimal that this multipliable object represents and the scale of 319 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 320 * product is out of the possible range for a {@code Decimal5f}. 321 * <p> 322 * Note that the result is <i>always</i> a new instance. 323 * 324 * @param factor 325 * the factor to multiply with the Decimal that this multipliable represents 326 * @return <tt>(this * factor)</tt> 327 * @throws ArithmeticException 328 * if an overflow occurs and product is out of the possible 329 * range for a {@code Decimal5f} 330 */ 331 public Decimal5f by(MutableDecimal5f factor) { 332 return Decimal5f.valueOf(this.value.multiplyExact(factor)); 333 } 334 335 /** 336 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 337 * result is exact and has scale 6 which is the sum of the scales 338 * of the Decimal that this multipliable object represents and the scale of 339 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 340 * product is out of the possible range for a {@code Decimal6f}. 341 * <p> 342 * Note that the result is <i>always</i> a new instance. 343 * 344 * @param factor 345 * the factor to multiply with the Decimal that this multipliable represents 346 * @return <tt>(this * factor)</tt> 347 * @throws ArithmeticException 348 * if an overflow occurs and product is out of the possible 349 * range for a {@code Decimal6f} 350 */ 351 public Decimal6f by(Decimal6f factor) { 352 return Decimal6f.valueOf(this.value.multiplyExact(factor)); 353 } 354 /** 355 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 356 * result is exact and has scale 6 which is the sum of the scales 357 * of the Decimal that this multipliable object represents and the scale of 358 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 359 * product is out of the possible range for a {@code Decimal6f}. 360 * <p> 361 * Note that the result is <i>always</i> a new instance. 362 * 363 * @param factor 364 * the factor to multiply with the Decimal that this multipliable represents 365 * @return <tt>(this * factor)</tt> 366 * @throws ArithmeticException 367 * if an overflow occurs and product is out of the possible 368 * range for a {@code Decimal6f} 369 */ 370 public Decimal6f by(MutableDecimal6f factor) { 371 return Decimal6f.valueOf(this.value.multiplyExact(factor)); 372 } 373 374 /** 375 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 376 * result is exact and has scale 7 which is the sum of the scales 377 * of the Decimal that this multipliable object represents and the scale of 378 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 379 * product is out of the possible range for a {@code Decimal7f}. 380 * <p> 381 * Note that the result is <i>always</i> a new instance. 382 * 383 * @param factor 384 * the factor to multiply with the Decimal that this multipliable represents 385 * @return <tt>(this * factor)</tt> 386 * @throws ArithmeticException 387 * if an overflow occurs and product is out of the possible 388 * range for a {@code Decimal7f} 389 */ 390 public Decimal7f by(Decimal7f factor) { 391 return Decimal7f.valueOf(this.value.multiplyExact(factor)); 392 } 393 /** 394 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 395 * result is exact and has scale 7 which is the sum of the scales 396 * of the Decimal that this multipliable object represents and the scale of 397 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 398 * product is out of the possible range for a {@code Decimal7f}. 399 * <p> 400 * Note that the result is <i>always</i> a new instance. 401 * 402 * @param factor 403 * the factor to multiply with the Decimal that this multipliable represents 404 * @return <tt>(this * factor)</tt> 405 * @throws ArithmeticException 406 * if an overflow occurs and product is out of the possible 407 * range for a {@code Decimal7f} 408 */ 409 public Decimal7f by(MutableDecimal7f factor) { 410 return Decimal7f.valueOf(this.value.multiplyExact(factor)); 411 } 412 413 /** 414 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 415 * result is exact and has scale 8 which is the sum of the scales 416 * of the Decimal that this multipliable object represents and the scale of 417 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 418 * product is out of the possible range for a {@code Decimal8f}. 419 * <p> 420 * Note that the result is <i>always</i> a new instance. 421 * 422 * @param factor 423 * the factor to multiply with the Decimal that this multipliable represents 424 * @return <tt>(this * factor)</tt> 425 * @throws ArithmeticException 426 * if an overflow occurs and product is out of the possible 427 * range for a {@code Decimal8f} 428 */ 429 public Decimal8f by(Decimal8f factor) { 430 return Decimal8f.valueOf(this.value.multiplyExact(factor)); 431 } 432 /** 433 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 434 * result is exact and has scale 8 which is the sum of the scales 435 * of the Decimal that this multipliable object represents and the scale of 436 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 437 * product is out of the possible range for a {@code Decimal8f}. 438 * <p> 439 * Note that the result is <i>always</i> a new instance. 440 * 441 * @param factor 442 * the factor to multiply with the Decimal that this multipliable represents 443 * @return <tt>(this * factor)</tt> 444 * @throws ArithmeticException 445 * if an overflow occurs and product is out of the possible 446 * range for a {@code Decimal8f} 447 */ 448 public Decimal8f by(MutableDecimal8f factor) { 449 return Decimal8f.valueOf(this.value.multiplyExact(factor)); 450 } 451 452 /** 453 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 454 * result is exact and has scale 9 which is the sum of the scales 455 * of the Decimal that this multipliable object represents and the scale of 456 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 457 * product is out of the possible range for a {@code Decimal9f}. 458 * <p> 459 * Note that the result is <i>always</i> a new instance. 460 * 461 * @param factor 462 * the factor to multiply with the Decimal that this multipliable represents 463 * @return <tt>(this * factor)</tt> 464 * @throws ArithmeticException 465 * if an overflow occurs and product is out of the possible 466 * range for a {@code Decimal9f} 467 */ 468 public Decimal9f by(Decimal9f factor) { 469 return Decimal9f.valueOf(this.value.multiplyExact(factor)); 470 } 471 /** 472 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 473 * result is exact and has scale 9 which is the sum of the scales 474 * of the Decimal that this multipliable object represents and the scale of 475 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 476 * product is out of the possible range for a {@code Decimal9f}. 477 * <p> 478 * Note that the result is <i>always</i> a new instance. 479 * 480 * @param factor 481 * the factor to multiply with the Decimal that this multipliable represents 482 * @return <tt>(this * factor)</tt> 483 * @throws ArithmeticException 484 * if an overflow occurs and product is out of the possible 485 * range for a {@code Decimal9f} 486 */ 487 public Decimal9f by(MutableDecimal9f factor) { 488 return Decimal9f.valueOf(this.value.multiplyExact(factor)); 489 } 490 491 /** 492 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 493 * result is exact and has scale 10 which is the sum of the scales 494 * of the Decimal that this multipliable object represents and the scale of 495 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 496 * product is out of the possible range for a {@code Decimal10f}. 497 * <p> 498 * Note that the result is <i>always</i> a new instance. 499 * 500 * @param factor 501 * the factor to multiply with the Decimal that this multipliable represents 502 * @return <tt>(this * factor)</tt> 503 * @throws ArithmeticException 504 * if an overflow occurs and product is out of the possible 505 * range for a {@code Decimal10f} 506 */ 507 public Decimal10f by(Decimal10f factor) { 508 return Decimal10f.valueOf(this.value.multiplyExact(factor)); 509 } 510 /** 511 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 512 * result is exact and has scale 10 which is the sum of the scales 513 * of the Decimal that this multipliable object represents and the scale of 514 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 515 * product is out of the possible range for a {@code Decimal10f}. 516 * <p> 517 * Note that the result is <i>always</i> a new instance. 518 * 519 * @param factor 520 * the factor to multiply with the Decimal that this multipliable represents 521 * @return <tt>(this * factor)</tt> 522 * @throws ArithmeticException 523 * if an overflow occurs and product is out of the possible 524 * range for a {@code Decimal10f} 525 */ 526 public Decimal10f by(MutableDecimal10f factor) { 527 return Decimal10f.valueOf(this.value.multiplyExact(factor)); 528 } 529 530 /** 531 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 532 * result is exact and has scale 11 which is the sum of the scales 533 * of the Decimal that this multipliable object represents and the scale of 534 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 535 * product is out of the possible range for a {@code Decimal11f}. 536 * <p> 537 * Note that the result is <i>always</i> a new instance. 538 * 539 * @param factor 540 * the factor to multiply with the Decimal that this multipliable represents 541 * @return <tt>(this * factor)</tt> 542 * @throws ArithmeticException 543 * if an overflow occurs and product is out of the possible 544 * range for a {@code Decimal11f} 545 */ 546 public Decimal11f by(Decimal11f factor) { 547 return Decimal11f.valueOf(this.value.multiplyExact(factor)); 548 } 549 /** 550 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 551 * result is exact and has scale 11 which is the sum of the scales 552 * of the Decimal that this multipliable object represents and the scale of 553 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 554 * product is out of the possible range for a {@code Decimal11f}. 555 * <p> 556 * Note that the result is <i>always</i> a new instance. 557 * 558 * @param factor 559 * the factor to multiply with the Decimal that this multipliable represents 560 * @return <tt>(this * factor)</tt> 561 * @throws ArithmeticException 562 * if an overflow occurs and product is out of the possible 563 * range for a {@code Decimal11f} 564 */ 565 public Decimal11f by(MutableDecimal11f factor) { 566 return Decimal11f.valueOf(this.value.multiplyExact(factor)); 567 } 568 569 /** 570 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 571 * result is exact and has scale 12 which is the sum of the scales 572 * of the Decimal that this multipliable object represents and the scale of 573 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 574 * product is out of the possible range for a {@code Decimal12f}. 575 * <p> 576 * Note that the result is <i>always</i> a new instance. 577 * 578 * @param factor 579 * the factor to multiply with the Decimal that this multipliable represents 580 * @return <tt>(this * factor)</tt> 581 * @throws ArithmeticException 582 * if an overflow occurs and product is out of the possible 583 * range for a {@code Decimal12f} 584 */ 585 public Decimal12f by(Decimal12f factor) { 586 return Decimal12f.valueOf(this.value.multiplyExact(factor)); 587 } 588 /** 589 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 590 * result is exact and has scale 12 which is the sum of the scales 591 * of the Decimal that this multipliable object represents and the scale of 592 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 593 * product is out of the possible range for a {@code Decimal12f}. 594 * <p> 595 * Note that the result is <i>always</i> a new instance. 596 * 597 * @param factor 598 * the factor to multiply with the Decimal that this multipliable represents 599 * @return <tt>(this * factor)</tt> 600 * @throws ArithmeticException 601 * if an overflow occurs and product is out of the possible 602 * range for a {@code Decimal12f} 603 */ 604 public Decimal12f by(MutableDecimal12f factor) { 605 return Decimal12f.valueOf(this.value.multiplyExact(factor)); 606 } 607 608 /** 609 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 610 * result is exact and has scale 13 which is the sum of the scales 611 * of the Decimal that this multipliable object represents and the scale of 612 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 613 * product is out of the possible range for a {@code Decimal13f}. 614 * <p> 615 * Note that the result is <i>always</i> a new instance. 616 * 617 * @param factor 618 * the factor to multiply with the Decimal that this multipliable represents 619 * @return <tt>(this * factor)</tt> 620 * @throws ArithmeticException 621 * if an overflow occurs and product is out of the possible 622 * range for a {@code Decimal13f} 623 */ 624 public Decimal13f by(Decimal13f factor) { 625 return Decimal13f.valueOf(this.value.multiplyExact(factor)); 626 } 627 /** 628 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 629 * result is exact and has scale 13 which is the sum of the scales 630 * of the Decimal that this multipliable object represents and the scale of 631 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 632 * product is out of the possible range for a {@code Decimal13f}. 633 * <p> 634 * Note that the result is <i>always</i> a new instance. 635 * 636 * @param factor 637 * the factor to multiply with the Decimal that this multipliable represents 638 * @return <tt>(this * factor)</tt> 639 * @throws ArithmeticException 640 * if an overflow occurs and product is out of the possible 641 * range for a {@code Decimal13f} 642 */ 643 public Decimal13f by(MutableDecimal13f factor) { 644 return Decimal13f.valueOf(this.value.multiplyExact(factor)); 645 } 646 647 /** 648 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 649 * result is exact and has scale 14 which is the sum of the scales 650 * of the Decimal that this multipliable object represents and the scale of 651 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 652 * product is out of the possible range for a {@code Decimal14f}. 653 * <p> 654 * Note that the result is <i>always</i> a new instance. 655 * 656 * @param factor 657 * the factor to multiply with the Decimal that this multipliable represents 658 * @return <tt>(this * factor)</tt> 659 * @throws ArithmeticException 660 * if an overflow occurs and product is out of the possible 661 * range for a {@code Decimal14f} 662 */ 663 public Decimal14f by(Decimal14f factor) { 664 return Decimal14f.valueOf(this.value.multiplyExact(factor)); 665 } 666 /** 667 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 668 * result is exact and has scale 14 which is the sum of the scales 669 * of the Decimal that this multipliable object represents and the scale of 670 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 671 * product is out of the possible range for a {@code Decimal14f}. 672 * <p> 673 * Note that the result is <i>always</i> a new instance. 674 * 675 * @param factor 676 * the factor to multiply with the Decimal that this multipliable represents 677 * @return <tt>(this * factor)</tt> 678 * @throws ArithmeticException 679 * if an overflow occurs and product is out of the possible 680 * range for a {@code Decimal14f} 681 */ 682 public Decimal14f by(MutableDecimal14f factor) { 683 return Decimal14f.valueOf(this.value.multiplyExact(factor)); 684 } 685 686 /** 687 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 688 * result is exact and has scale 15 which is the sum of the scales 689 * of the Decimal that this multipliable object represents and the scale of 690 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 691 * product is out of the possible range for a {@code Decimal15f}. 692 * <p> 693 * Note that the result is <i>always</i> a new instance. 694 * 695 * @param factor 696 * the factor to multiply with the Decimal that this multipliable represents 697 * @return <tt>(this * factor)</tt> 698 * @throws ArithmeticException 699 * if an overflow occurs and product is out of the possible 700 * range for a {@code Decimal15f} 701 */ 702 public Decimal15f by(Decimal15f factor) { 703 return Decimal15f.valueOf(this.value.multiplyExact(factor)); 704 } 705 /** 706 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 707 * result is exact and has scale 15 which is the sum of the scales 708 * of the Decimal that this multipliable object represents and the scale of 709 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 710 * product is out of the possible range for a {@code Decimal15f}. 711 * <p> 712 * Note that the result is <i>always</i> a new instance. 713 * 714 * @param factor 715 * the factor to multiply with the Decimal that this multipliable represents 716 * @return <tt>(this * factor)</tt> 717 * @throws ArithmeticException 718 * if an overflow occurs and product is out of the possible 719 * range for a {@code Decimal15f} 720 */ 721 public Decimal15f by(MutableDecimal15f factor) { 722 return Decimal15f.valueOf(this.value.multiplyExact(factor)); 723 } 724 725 /** 726 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 727 * result is exact and has scale 16 which is the sum of the scales 728 * of the Decimal that this multipliable object represents and the scale of 729 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 730 * product is out of the possible range for a {@code Decimal16f}. 731 * <p> 732 * Note that the result is <i>always</i> a new instance. 733 * 734 * @param factor 735 * the factor to multiply with the Decimal that this multipliable represents 736 * @return <tt>(this * factor)</tt> 737 * @throws ArithmeticException 738 * if an overflow occurs and product is out of the possible 739 * range for a {@code Decimal16f} 740 */ 741 public Decimal16f by(Decimal16f factor) { 742 return Decimal16f.valueOf(this.value.multiplyExact(factor)); 743 } 744 /** 745 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 746 * result is exact and has scale 16 which is the sum of the scales 747 * of the Decimal that this multipliable object represents and the scale of 748 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 749 * product is out of the possible range for a {@code Decimal16f}. 750 * <p> 751 * Note that the result is <i>always</i> a new instance. 752 * 753 * @param factor 754 * the factor to multiply with the Decimal that this multipliable represents 755 * @return <tt>(this * factor)</tt> 756 * @throws ArithmeticException 757 * if an overflow occurs and product is out of the possible 758 * range for a {@code Decimal16f} 759 */ 760 public Decimal16f by(MutableDecimal16f factor) { 761 return Decimal16f.valueOf(this.value.multiplyExact(factor)); 762 } 763 764 /** 765 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 766 * result is exact and has scale 17 which is the sum of the scales 767 * of the Decimal that this multipliable object represents and the scale of 768 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 769 * product is out of the possible range for a {@code Decimal17f}. 770 * <p> 771 * Note that the result is <i>always</i> a new instance. 772 * 773 * @param factor 774 * the factor to multiply with the Decimal that this multipliable represents 775 * @return <tt>(this * factor)</tt> 776 * @throws ArithmeticException 777 * if an overflow occurs and product is out of the possible 778 * range for a {@code Decimal17f} 779 */ 780 public Decimal17f by(Decimal17f factor) { 781 return Decimal17f.valueOf(this.value.multiplyExact(factor)); 782 } 783 /** 784 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 785 * result is exact and has scale 17 which is the sum of the scales 786 * of the Decimal that this multipliable object represents and the scale of 787 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 788 * product is out of the possible range for a {@code Decimal17f}. 789 * <p> 790 * Note that the result is <i>always</i> a new instance. 791 * 792 * @param factor 793 * the factor to multiply with the Decimal that this multipliable represents 794 * @return <tt>(this * factor)</tt> 795 * @throws ArithmeticException 796 * if an overflow occurs and product is out of the possible 797 * range for a {@code Decimal17f} 798 */ 799 public Decimal17f by(MutableDecimal17f factor) { 800 return Decimal17f.valueOf(this.value.multiplyExact(factor)); 801 } 802 803 /** 804 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 805 * result is exact and has scale 18 which is the sum of the scales 806 * of the Decimal that this multipliable object represents and the scale of 807 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 808 * product is out of the possible range for a {@code Decimal18f}. 809 * <p> 810 * Note that the result is <i>always</i> a new instance. 811 * 812 * @param factor 813 * the factor to multiply with the Decimal that this multipliable represents 814 * @return <tt>(this * factor)</tt> 815 * @throws ArithmeticException 816 * if an overflow occurs and product is out of the possible 817 * range for a {@code Decimal18f} 818 */ 819 public Decimal18f by(Decimal18f factor) { 820 return Decimal18f.valueOf(this.value.multiplyExact(factor)); 821 } 822 /** 823 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 824 * result is exact and has scale 18 which is the sum of the scales 825 * of the Decimal that this multipliable object represents and the scale of 826 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 827 * product is out of the possible range for a {@code Decimal18f}. 828 * <p> 829 * Note that the result is <i>always</i> a new instance. 830 * 831 * @param factor 832 * the factor to multiply with the Decimal that this multipliable represents 833 * @return <tt>(this * factor)</tt> 834 * @throws ArithmeticException 835 * if an overflow occurs and product is out of the possible 836 * range for a {@code Decimal18f} 837 */ 838 public Decimal18f by(MutableDecimal18f factor) { 839 return Decimal18f.valueOf(this.value.multiplyExact(factor)); 840 } 841 842 843 /** 844 * Returns a hash code for this <tt>Multipliable0f</tt> which happens to be the 845 * hash code of the underlying {@code Decimal0f} value. 846 * 847 * @return a hash code value for this object 848 * @see Decimal#hashCode() 849 */ 850 @Override 851 public int hashCode() { 852 return value.hashCode(); 853 } 854 855 /** 856 * Compares this Multipliable0f to the specified object. The result is {@code true} 857 * if and only if the argument is a {@code Multipliable0f} with an equal underlying 858 * {@link #getValue() value}. 859 * 860 * @param obj 861 * the object to compare with 862 * @return {@code true} if the argument is a {@code Multipliable0f} and if its value 863 * is equal to this multipliables's value; {@code false} otherwise 864 * @see #getValue() 865 * @see Decimal#equals(Object) 866 */ 867 @Override 868 public boolean equals(Object obj) { 869 if (this == obj) return true; 870 if (obj == null) return false; 871 if (getClass() != obj.getClass()) return false; 872 return value.equals(((Multipliable0f)obj).value); 873 } 874 875 /** 876 * Returns a string representation of this {@code Multipliable0f} which is 877 * simply the string representation of the underlying Decimal {@link #getValue() value}. 878 * 879 * @return a {@code String} Decimal representation of this {@code Multipliable0f}'s 880 * value with all the fraction digits (including trailing zeros) 881 * @see #getValue() 882 * @see Decimal#toString() 883 */ 884 @Override 885 public String toString() { 886 return value.toString(); 887 } 888}