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