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