1
/* NSDecimal types and functions
2
Copyright (C) 1998 Free Software Foundation, Inc.
4
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
7
This file is part of the GNUstep Base Library.
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Library General Public
11
License as published by the Free Software Foundation; either
12
version 2 of the License, or (at your option) any later version.
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Library General Public License for more details.
19
You should have received a copy of the GNU Library General Public
20
License along with this library; if not, write to the Free
21
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
24
#ifndef __NSDecimal_h_GNUSTEP_BASE_INCLUDE
25
#define __NSDecimal_h_GNUSTEP_BASE_INCLUDE
27
#ifndef STRICT_OPENSTEP
35
#include <Foundation/NSObject.h>
40
NSRoundPlain, /* Round .5 up */
41
NSRoundBankers /* Make last digit even */
45
NSCalculationNoError = 0,
46
NSCalculationUnderflow, /* result became zero */
47
NSCalculationOverflow,
48
NSCalculationLossOfPrecision,
49
NSCalculationDivideByZero
53
* Give a precision of at least 38 decimal digits
56
#define NSDecimalMaxSize (16/sizeof(mp_limb_t))
58
#define NSDecimalMaxDigit 38
59
#define NSDecimalNoScale 128
62
signed char exponent; /* Signed exponent - -128 to 127 */
63
BOOL isNegative; /* Is this negative? */
64
BOOL validNumber; /* Is this a valid number? */
67
mp_limb_t lMantissa[NSDecimalMaxSize];
69
unsigned char length; /* digits in mantissa. */
70
unsigned char cMantissa[NSDecimalMaxDigit];
75
NSDecimalIsNotANumber(const NSDecimal *decimal)
77
return (decimal->validNumber == NO);
81
NSDecimalCopy(NSDecimal *destination, const NSDecimal *source);
84
NSDecimalCompact(NSDecimal *number);
86
GS_EXPORT NSComparisonResult
87
NSDecimalCompare(const NSDecimal *leftOperand, const NSDecimal *rightOperand);
90
NSDecimalRound(NSDecimal *result, const NSDecimal *number, int scale, NSRoundingMode mode);
92
GS_EXPORT NSCalculationError
93
NSDecimalNormalize(NSDecimal *n1, NSDecimal *n2, NSRoundingMode mode);
95
GS_EXPORT NSCalculationError
96
NSDecimalAdd(NSDecimal *result, const NSDecimal *left, const NSDecimal *right, NSRoundingMode mode);
98
GS_EXPORT NSCalculationError
99
NSDecimalSubtract(NSDecimal *result, const NSDecimal *left, const NSDecimal *right, NSRoundingMode mode);
101
GS_EXPORT NSCalculationError
102
NSDecimalMultiply(NSDecimal *result, const NSDecimal *l, const NSDecimal *r, NSRoundingMode mode);
104
GS_EXPORT NSCalculationError
105
NSDecimalDivide(NSDecimal *result, const NSDecimal *l, const NSDecimal *rr, NSRoundingMode mode);
107
GS_EXPORT NSCalculationError
108
NSDecimalPower(NSDecimal *result, const NSDecimal *n, unsigned power, NSRoundingMode mode);
110
GS_EXPORT NSCalculationError
111
NSDecimalMultiplyByPowerOf10(NSDecimal *result, const NSDecimal *n, short power, NSRoundingMode mode);
114
NSDecimalString(const NSDecimal *decimal, NSDictionary *locale);
117
// GNUstep extensions to make the implementation of NSDecimalNumber totaly
118
// independent for NSDecimals internal representation
120
// Give back the biggest NSDecimal
122
NSDecimalMax(NSDecimal *result);
124
// Give back the smallest NSDecimal
126
NSDecimalMin(NSDecimal *result);
128
// Give back the value of a NSDecimal as a double
130
NSDecimalDouble(NSDecimal *number);
132
// Create a NSDecimal with a mantissa, exponent and a negative flag
134
NSDecimalFromComponents(NSDecimal *result, unsigned long long mantissa,
135
short exponent, BOOL negative);
137
// Create a NSDecimal from a string using the local
139
NSDecimalFromString(NSDecimal *result, NSString *numberValue,
140
NSDictionary *locale);