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