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