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