001/* 002 * The MIT License (MIT) 003 * 004 * Copyright (c) 2015-2024 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.MutableDecimal3f; 052import org.decimal4j.mutable.MutableDecimal4f; 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.scale.Scale5f; 062 063/** 064 * A {@code Multipliable5f} encapsulates a Decimal of scale 5 and facilitates 065 * exact typed multiplication. The multipliable object acts as first factor in the multiplication 066 * and provides a set of overloaded methods for different scales. Each one of those methods 067 * delivers a different result scale which represents the appropriate scale for the product of 068 * an exact multiplication. 069 * <p> 070 * A {@code Multipliable5f} object is returned by {@link Decimal5f#multiplyExact()}, 071 * hence an exact typed multiplication can be written as: 072 * <pre> 073 * Decimal5f value = ... //some value 074 * Decimal7f product = value.multiplyExact().by(Decimal2f.FIVE); 075 * </pre> 076 */ 077public final class Multipliable5f { 078 079 private final Decimal<Scale5f> value; 080 081 /** 082 * Constructor with Decimal value to be encapsulated. 083 * @param value the decimal value to be wrapped as a multipliable object 084 */ 085 public Multipliable5f(Decimal<Scale5f> value) { 086 this.value = Objects.requireNonNull(value, "value cannot be null"); 087 } 088 089 /** 090 * Returns the value underlying this Multipliable5f. 091 * @return the Decimal value wrapped by this multipliable object 092 */ 093 public Decimal<Scale5f> getValue() { 094 return value; 095 } 096 097 /** 098 * Returns a {@code Decimal} whose value is <code>(this<sup>2</sup>)</code>. The 099 * result is exact and has scale 10 which is twice the scale of 100 * the Decimal that this multipliable object represents. An 101 * {@link ArithmeticException} is thrown if the product is out of the 102 * possible range for a {@code Decimal10f}. 103 * <p> 104 * Note that the result is <i>always</i> a new instance. 105 * 106 * @return <code>(this * this)</code> 107 * @throws ArithmeticException 108 * if an overflow occurs and product is out of the possible 109 * range for a {@code Decimal10f} 110 */ 111 public Decimal10f square() { 112 return by(this.value); 113 } 114 115 /** 116 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 117 * result is exact and has scale 10 which is the sum of the scales 118 * of the Decimal that this multipliable object represents and the scale of 119 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 120 * product is out of the possible range for a {@code Decimal10f}. 121 * <p> 122 * Note that the result is <i>always</i> a new instance. 123 * 124 * @param factor 125 * the factor to multiply with the Decimal that this multipliable represents 126 * @return <code>(this * factor)</code> 127 * @throws ArithmeticException 128 * if an overflow occurs and product is out of the possible 129 * range for a {@code Decimal10f} 130 */ 131 public Decimal10f by(Decimal<Scale5f> factor) { 132 return Decimal10f.valueOf(this.value.multiplyExact(factor)); 133 } 134 135 /** 136 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 137 * result is exact and has scale 5 which is the sum of the scales 138 * of the Decimal that this multipliable object represents and the scale of 139 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 140 * product is out of the possible range for a {@code Decimal5f}. 141 * <p> 142 * Note that the result is <i>always</i> a new instance. 143 * 144 * @param factor 145 * the factor to multiply with the Decimal that this multipliable represents 146 * @return <code>(this * factor)</code> 147 * @throws ArithmeticException 148 * if an overflow occurs and product is out of the possible 149 * range for a {@code Decimal5f} 150 */ 151 public Decimal5f by(Decimal0f factor) { 152 return Decimal5f.valueOf(this.value.multiplyExact(factor)); 153 } 154 /** 155 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 156 * result is exact and has scale 5 which is the sum of the scales 157 * of the Decimal that this multipliable object represents and the scale of 158 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 159 * product is out of the possible range for a {@code Decimal5f}. 160 * <p> 161 * Note that the result is <i>always</i> a new instance. 162 * 163 * @param factor 164 * the factor to multiply with the Decimal that this multipliable represents 165 * @return <code>(this * factor)</code> 166 * @throws ArithmeticException 167 * if an overflow occurs and product is out of the possible 168 * range for a {@code Decimal5f} 169 */ 170 public Decimal5f by(MutableDecimal0f factor) { 171 return Decimal5f.valueOf(this.value.multiplyExact(factor)); 172 } 173 174 /** 175 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 176 * result is exact and has scale 6 which is the sum of the scales 177 * of the Decimal that this multipliable object represents and the scale of 178 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 179 * product is out of the possible range for a {@code Decimal6f}. 180 * <p> 181 * Note that the result is <i>always</i> a new instance. 182 * 183 * @param factor 184 * the factor to multiply with the Decimal that this multipliable represents 185 * @return <code>(this * factor)</code> 186 * @throws ArithmeticException 187 * if an overflow occurs and product is out of the possible 188 * range for a {@code Decimal6f} 189 */ 190 public Decimal6f by(Decimal1f factor) { 191 return Decimal6f.valueOf(this.value.multiplyExact(factor)); 192 } 193 /** 194 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 195 * result is exact and has scale 6 which is the sum of the scales 196 * of the Decimal that this multipliable object represents and the scale of 197 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 198 * product is out of the possible range for a {@code Decimal6f}. 199 * <p> 200 * Note that the result is <i>always</i> a new instance. 201 * 202 * @param factor 203 * the factor to multiply with the Decimal that this multipliable represents 204 * @return <code>(this * factor)</code> 205 * @throws ArithmeticException 206 * if an overflow occurs and product is out of the possible 207 * range for a {@code Decimal6f} 208 */ 209 public Decimal6f by(MutableDecimal1f factor) { 210 return Decimal6f.valueOf(this.value.multiplyExact(factor)); 211 } 212 213 /** 214 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 215 * result is exact and has scale 7 which is the sum of the scales 216 * of the Decimal that this multipliable object represents and the scale of 217 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 218 * product is out of the possible range for a {@code Decimal7f}. 219 * <p> 220 * Note that the result is <i>always</i> a new instance. 221 * 222 * @param factor 223 * the factor to multiply with the Decimal that this multipliable represents 224 * @return <code>(this * factor)</code> 225 * @throws ArithmeticException 226 * if an overflow occurs and product is out of the possible 227 * range for a {@code Decimal7f} 228 */ 229 public Decimal7f by(Decimal2f factor) { 230 return Decimal7f.valueOf(this.value.multiplyExact(factor)); 231 } 232 /** 233 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 234 * result is exact and has scale 7 which is the sum of the scales 235 * of the Decimal that this multipliable object represents and the scale of 236 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 237 * product is out of the possible range for a {@code Decimal7f}. 238 * <p> 239 * Note that the result is <i>always</i> a new instance. 240 * 241 * @param factor 242 * the factor to multiply with the Decimal that this multipliable represents 243 * @return <code>(this * factor)</code> 244 * @throws ArithmeticException 245 * if an overflow occurs and product is out of the possible 246 * range for a {@code Decimal7f} 247 */ 248 public Decimal7f by(MutableDecimal2f factor) { 249 return Decimal7f.valueOf(this.value.multiplyExact(factor)); 250 } 251 252 /** 253 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 254 * result is exact and has scale 8 which is the sum of the scales 255 * of the Decimal that this multipliable object represents and the scale of 256 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 257 * product is out of the possible range for a {@code Decimal8f}. 258 * <p> 259 * Note that the result is <i>always</i> a new instance. 260 * 261 * @param factor 262 * the factor to multiply with the Decimal that this multipliable represents 263 * @return <code>(this * factor)</code> 264 * @throws ArithmeticException 265 * if an overflow occurs and product is out of the possible 266 * range for a {@code Decimal8f} 267 */ 268 public Decimal8f by(Decimal3f factor) { 269 return Decimal8f.valueOf(this.value.multiplyExact(factor)); 270 } 271 /** 272 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 273 * result is exact and has scale 8 which is the sum of the scales 274 * of the Decimal that this multipliable object represents and the scale of 275 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 276 * product is out of the possible range for a {@code Decimal8f}. 277 * <p> 278 * Note that the result is <i>always</i> a new instance. 279 * 280 * @param factor 281 * the factor to multiply with the Decimal that this multipliable represents 282 * @return <code>(this * factor)</code> 283 * @throws ArithmeticException 284 * if an overflow occurs and product is out of the possible 285 * range for a {@code Decimal8f} 286 */ 287 public Decimal8f by(MutableDecimal3f factor) { 288 return Decimal8f.valueOf(this.value.multiplyExact(factor)); 289 } 290 291 /** 292 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 293 * result is exact and has scale 9 which is the sum of the scales 294 * of the Decimal that this multipliable object represents and the scale of 295 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 296 * product is out of the possible range for a {@code Decimal9f}. 297 * <p> 298 * Note that the result is <i>always</i> a new instance. 299 * 300 * @param factor 301 * the factor to multiply with the Decimal that this multipliable represents 302 * @return <code>(this * factor)</code> 303 * @throws ArithmeticException 304 * if an overflow occurs and product is out of the possible 305 * range for a {@code Decimal9f} 306 */ 307 public Decimal9f by(Decimal4f factor) { 308 return Decimal9f.valueOf(this.value.multiplyExact(factor)); 309 } 310 /** 311 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 312 * result is exact and has scale 9 which is the sum of the scales 313 * of the Decimal that this multipliable object represents and the scale of 314 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 315 * product is out of the possible range for a {@code Decimal9f}. 316 * <p> 317 * Note that the result is <i>always</i> a new instance. 318 * 319 * @param factor 320 * the factor to multiply with the Decimal that this multipliable represents 321 * @return <code>(this * factor)</code> 322 * @throws ArithmeticException 323 * if an overflow occurs and product is out of the possible 324 * range for a {@code Decimal9f} 325 */ 326 public Decimal9f by(MutableDecimal4f factor) { 327 return Decimal9f.valueOf(this.value.multiplyExact(factor)); 328 } 329 330 /** 331 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 332 * result is exact and has scale 11 which is the sum of the scales 333 * of the Decimal that this multipliable object represents and the scale of 334 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 335 * product is out of the possible range for a {@code Decimal11f}. 336 * <p> 337 * Note that the result is <i>always</i> a new instance. 338 * 339 * @param factor 340 * the factor to multiply with the Decimal that this multipliable represents 341 * @return <code>(this * factor)</code> 342 * @throws ArithmeticException 343 * if an overflow occurs and product is out of the possible 344 * range for a {@code Decimal11f} 345 */ 346 public Decimal11f by(Decimal6f factor) { 347 return Decimal11f.valueOf(this.value.multiplyExact(factor)); 348 } 349 /** 350 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 351 * result is exact and has scale 11 which is the sum of the scales 352 * of the Decimal that this multipliable object represents and the scale of 353 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 354 * product is out of the possible range for a {@code Decimal11f}. 355 * <p> 356 * Note that the result is <i>always</i> a new instance. 357 * 358 * @param factor 359 * the factor to multiply with the Decimal that this multipliable represents 360 * @return <code>(this * factor)</code> 361 * @throws ArithmeticException 362 * if an overflow occurs and product is out of the possible 363 * range for a {@code Decimal11f} 364 */ 365 public Decimal11f by(MutableDecimal6f factor) { 366 return Decimal11f.valueOf(this.value.multiplyExact(factor)); 367 } 368 369 /** 370 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 371 * result is exact and has scale 12 which is the sum of the scales 372 * of the Decimal that this multipliable object represents and the scale of 373 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 374 * product is out of the possible range for a {@code Decimal12f}. 375 * <p> 376 * Note that the result is <i>always</i> a new instance. 377 * 378 * @param factor 379 * the factor to multiply with the Decimal that this multipliable represents 380 * @return <code>(this * factor)</code> 381 * @throws ArithmeticException 382 * if an overflow occurs and product is out of the possible 383 * range for a {@code Decimal12f} 384 */ 385 public Decimal12f by(Decimal7f factor) { 386 return Decimal12f.valueOf(this.value.multiplyExact(factor)); 387 } 388 /** 389 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 390 * result is exact and has scale 12 which is the sum of the scales 391 * of the Decimal that this multipliable object represents and the scale of 392 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 393 * product is out of the possible range for a {@code Decimal12f}. 394 * <p> 395 * Note that the result is <i>always</i> a new instance. 396 * 397 * @param factor 398 * the factor to multiply with the Decimal that this multipliable represents 399 * @return <code>(this * factor)</code> 400 * @throws ArithmeticException 401 * if an overflow occurs and product is out of the possible 402 * range for a {@code Decimal12f} 403 */ 404 public Decimal12f by(MutableDecimal7f factor) { 405 return Decimal12f.valueOf(this.value.multiplyExact(factor)); 406 } 407 408 /** 409 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 410 * result is exact and has scale 13 which is the sum of the scales 411 * of the Decimal that this multipliable object represents and the scale of 412 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 413 * product is out of the possible range for a {@code Decimal13f}. 414 * <p> 415 * Note that the result is <i>always</i> a new instance. 416 * 417 * @param factor 418 * the factor to multiply with the Decimal that this multipliable represents 419 * @return <code>(this * factor)</code> 420 * @throws ArithmeticException 421 * if an overflow occurs and product is out of the possible 422 * range for a {@code Decimal13f} 423 */ 424 public Decimal13f by(Decimal8f factor) { 425 return Decimal13f.valueOf(this.value.multiplyExact(factor)); 426 } 427 /** 428 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 429 * result is exact and has scale 13 which is the sum of the scales 430 * of the Decimal that this multipliable object represents and the scale of 431 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 432 * product is out of the possible range for a {@code Decimal13f}. 433 * <p> 434 * Note that the result is <i>always</i> a new instance. 435 * 436 * @param factor 437 * the factor to multiply with the Decimal that this multipliable represents 438 * @return <code>(this * factor)</code> 439 * @throws ArithmeticException 440 * if an overflow occurs and product is out of the possible 441 * range for a {@code Decimal13f} 442 */ 443 public Decimal13f by(MutableDecimal8f factor) { 444 return Decimal13f.valueOf(this.value.multiplyExact(factor)); 445 } 446 447 /** 448 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 449 * result is exact and has scale 14 which is the sum of the scales 450 * of the Decimal that this multipliable object represents and the scale of 451 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 452 * product is out of the possible range for a {@code Decimal14f}. 453 * <p> 454 * Note that the result is <i>always</i> a new instance. 455 * 456 * @param factor 457 * the factor to multiply with the Decimal that this multipliable represents 458 * @return <code>(this * factor)</code> 459 * @throws ArithmeticException 460 * if an overflow occurs and product is out of the possible 461 * range for a {@code Decimal14f} 462 */ 463 public Decimal14f by(Decimal9f factor) { 464 return Decimal14f.valueOf(this.value.multiplyExact(factor)); 465 } 466 /** 467 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 468 * result is exact and has scale 14 which is the sum of the scales 469 * of the Decimal that this multipliable object represents and the scale of 470 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 471 * product is out of the possible range for a {@code Decimal14f}. 472 * <p> 473 * Note that the result is <i>always</i> a new instance. 474 * 475 * @param factor 476 * the factor to multiply with the Decimal that this multipliable represents 477 * @return <code>(this * factor)</code> 478 * @throws ArithmeticException 479 * if an overflow occurs and product is out of the possible 480 * range for a {@code Decimal14f} 481 */ 482 public Decimal14f by(MutableDecimal9f factor) { 483 return Decimal14f.valueOf(this.value.multiplyExact(factor)); 484 } 485 486 /** 487 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 488 * result is exact and has scale 15 which is the sum of the scales 489 * of the Decimal that this multipliable object represents and the scale of 490 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 491 * product is out of the possible range for a {@code Decimal15f}. 492 * <p> 493 * Note that the result is <i>always</i> a new instance. 494 * 495 * @param factor 496 * the factor to multiply with the Decimal that this multipliable represents 497 * @return <code>(this * factor)</code> 498 * @throws ArithmeticException 499 * if an overflow occurs and product is out of the possible 500 * range for a {@code Decimal15f} 501 */ 502 public Decimal15f by(Decimal10f factor) { 503 return Decimal15f.valueOf(this.value.multiplyExact(factor)); 504 } 505 /** 506 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 507 * result is exact and has scale 15 which is the sum of the scales 508 * of the Decimal that this multipliable object represents and the scale of 509 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 510 * product is out of the possible range for a {@code Decimal15f}. 511 * <p> 512 * Note that the result is <i>always</i> a new instance. 513 * 514 * @param factor 515 * the factor to multiply with the Decimal that this multipliable represents 516 * @return <code>(this * factor)</code> 517 * @throws ArithmeticException 518 * if an overflow occurs and product is out of the possible 519 * range for a {@code Decimal15f} 520 */ 521 public Decimal15f by(MutableDecimal10f factor) { 522 return Decimal15f.valueOf(this.value.multiplyExact(factor)); 523 } 524 525 /** 526 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 527 * result is exact and has scale 16 which is the sum of the scales 528 * of the Decimal that this multipliable object represents and the scale of 529 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 530 * product is out of the possible range for a {@code Decimal16f}. 531 * <p> 532 * Note that the result is <i>always</i> a new instance. 533 * 534 * @param factor 535 * the factor to multiply with the Decimal that this multipliable represents 536 * @return <code>(this * factor)</code> 537 * @throws ArithmeticException 538 * if an overflow occurs and product is out of the possible 539 * range for a {@code Decimal16f} 540 */ 541 public Decimal16f by(Decimal11f factor) { 542 return Decimal16f.valueOf(this.value.multiplyExact(factor)); 543 } 544 /** 545 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 546 * result is exact and has scale 16 which is the sum of the scales 547 * of the Decimal that this multipliable object represents and the scale of 548 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 549 * product is out of the possible range for a {@code Decimal16f}. 550 * <p> 551 * Note that the result is <i>always</i> a new instance. 552 * 553 * @param factor 554 * the factor to multiply with the Decimal that this multipliable represents 555 * @return <code>(this * factor)</code> 556 * @throws ArithmeticException 557 * if an overflow occurs and product is out of the possible 558 * range for a {@code Decimal16f} 559 */ 560 public Decimal16f by(MutableDecimal11f factor) { 561 return Decimal16f.valueOf(this.value.multiplyExact(factor)); 562 } 563 564 /** 565 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 566 * result is exact and has scale 17 which is the sum of the scales 567 * of the Decimal that this multipliable object represents and the scale of 568 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 569 * product is out of the possible range for a {@code Decimal17f}. 570 * <p> 571 * Note that the result is <i>always</i> a new instance. 572 * 573 * @param factor 574 * the factor to multiply with the Decimal that this multipliable represents 575 * @return <code>(this * factor)</code> 576 * @throws ArithmeticException 577 * if an overflow occurs and product is out of the possible 578 * range for a {@code Decimal17f} 579 */ 580 public Decimal17f by(Decimal12f factor) { 581 return Decimal17f.valueOf(this.value.multiplyExact(factor)); 582 } 583 /** 584 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 585 * result is exact and has scale 17 which is the sum of the scales 586 * of the Decimal that this multipliable object represents and the scale of 587 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 588 * product is out of the possible range for a {@code Decimal17f}. 589 * <p> 590 * Note that the result is <i>always</i> a new instance. 591 * 592 * @param factor 593 * the factor to multiply with the Decimal that this multipliable represents 594 * @return <code>(this * factor)</code> 595 * @throws ArithmeticException 596 * if an overflow occurs and product is out of the possible 597 * range for a {@code Decimal17f} 598 */ 599 public Decimal17f by(MutableDecimal12f factor) { 600 return Decimal17f.valueOf(this.value.multiplyExact(factor)); 601 } 602 603 /** 604 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 605 * result is exact and has scale 18 which is the sum of the scales 606 * of the Decimal that this multipliable object represents and the scale of 607 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 608 * product is out of the possible range for a {@code Decimal18f}. 609 * <p> 610 * Note that the result is <i>always</i> a new instance. 611 * 612 * @param factor 613 * the factor to multiply with the Decimal that this multipliable represents 614 * @return <code>(this * factor)</code> 615 * @throws ArithmeticException 616 * if an overflow occurs and product is out of the possible 617 * range for a {@code Decimal18f} 618 */ 619 public Decimal18f by(Decimal13f factor) { 620 return Decimal18f.valueOf(this.value.multiplyExact(factor)); 621 } 622 /** 623 * Returns a {@code Decimal} whose value is {@code (this * factor)}. The 624 * result is exact and has scale 18 which is the sum of the scales 625 * of the Decimal that this multipliable object represents and the scale of 626 * the {@code factor} argument. An {@link ArithmeticException} is thrown if the 627 * product is out of the possible range for a {@code Decimal18f}. 628 * <p> 629 * Note that the result is <i>always</i> a new instance. 630 * 631 * @param factor 632 * the factor to multiply with the Decimal that this multipliable represents 633 * @return <code>(this * factor)</code> 634 * @throws ArithmeticException 635 * if an overflow occurs and product is out of the possible 636 * range for a {@code Decimal18f} 637 */ 638 public Decimal18f by(MutableDecimal13f factor) { 639 return Decimal18f.valueOf(this.value.multiplyExact(factor)); 640 } 641 642 643 /** 644 * Returns a hash code for this <code>Multipliable5f</code> which happens to be the 645 * hash code of the underlying {@code Decimal5f} value. 646 * 647 * @return a hash code value for this object 648 * @see Decimal#hashCode() 649 */ 650 @Override 651 public int hashCode() { 652 return value.hashCode(); 653 } 654 655 /** 656 * Compares this Multipliable5f to the specified object. The result is {@code true} 657 * if and only if the argument is a {@code Multipliable5f} with an equal underlying 658 * {@link #getValue() value}. 659 * 660 * @param obj 661 * the object to compare with 662 * @return {@code true} if the argument is a {@code Multipliable5f} and if its value 663 * is equal to this multipliables's value; {@code false} otherwise 664 * @see #getValue() 665 * @see Decimal#equals(Object) 666 */ 667 @Override 668 public boolean equals(Object obj) { 669 if (this == obj) return true; 670 if (obj == null) return false; 671 if (getClass() != obj.getClass()) return false; 672 return value.equals(((Multipliable5f)obj).value); 673 } 674 675 /** 676 * Returns a string representation of this {@code Multipliable5f} which is 677 * simply the string representation of the underlying Decimal {@link #getValue() value}. 678 * 679 * @return a {@code String} Decimal representation of this {@code Multipliable5f}'s 680 * value with all the fraction digits (including trailing zeros) 681 * @see #getValue() 682 * @see Decimal#toString() 683 */ 684 @Override 685 public String toString() { 686 return value.toString(); 687 } 688}