001/*
002 * The MIT License (MIT)
003 *
004 * Copyright (c) 2015-2023 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.arithmetic;
025
026import java.io.IOException;
027
028import org.decimal4j.scale.Scale0f;
029
030/**
031 * Base class for arithmetic implementations with overflow check for the special
032 * case with {@link Scale0f}, that is, for longs.
033 */
034abstract public class AbstractCheckedScale0fArithmetic extends AbstractCheckedArithmetic {
035
036        @Override
037        public final Scale0f getScaleMetrics() {
038                return Scale0f.INSTANCE;
039        }
040
041        @Override
042        public final int getScale() {
043                return 0;
044        }
045
046        @Override
047        public final long one() {
048                return 1;
049        }
050
051        @Override
052        public final long addLong(long uDecimal, long lValue) {
053                return Checked.add(this, uDecimal, lValue);
054        }
055
056        @Override
057        public final long subtractLong(long uDecimal, long lValue) {
058                return Checked.subtract(this, uDecimal, lValue);
059        }
060
061        @Override
062        public final long multiply(long uDecimal1, long uDecimal2) {
063                return Checked.multiplyByLong(this, uDecimal1, uDecimal2);
064        }
065
066        @Override
067        public final long square(long uDecimal) {
068                return Checked.multiplyByLong(this, uDecimal, uDecimal);
069        }
070
071        @Override
072        public final long fromLong(long value) {
073                return value;
074        }
075
076        @Override
077        public final long toLong(long uDecimal) {
078                return uDecimal;
079        }
080
081        @Override
082        public final String toString(long uDecimal) {
083                return StringConversion.longToString(uDecimal);
084        }
085        
086        @Override
087        public final void toString(long uDecimal, Appendable appendable) throws IOException {
088                StringConversion.longToString(uDecimal, appendable);
089        }
090
091}