~ubuntu-branches/ubuntu/karmic/gnustep-base/karmic

« back to all changes in this revision

Viewing changes to Headers/gnustep/base/NSDecimal.h

  • Committer: Bazaar Package Importer
  • Author(s): Eric Heintzmann
  • Date: 2005-04-17 00:14:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050417001438-enf0y07c9tku85z1
Tags: 1.10.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* NSDecimal types and functions
2
 
   Copyright (C) 1998 Free Software Foundation, Inc.
3
 
 
4
 
   Written by:  Richard Frith-Macdonald <richard@brainstorm.co.uk>
5
 
   Created: November 1998
6
 
 
7
 
   This file is part of the GNUstep Base Library.
8
 
 
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.
13
 
 
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.
18
 
 
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.
22
 
   */
23
 
 
24
 
#ifndef __NSDecimal_h_GNUSTEP_BASE_INCLUDE
25
 
#define __NSDecimal_h_GNUSTEP_BASE_INCLUDE
26
 
 
27
 
#ifndef STRICT_OPENSTEP
28
 
 
29
 
#include <GSConfig.h>
30
 
 
31
 
#if     HAVE_GMP
32
 
#include <gmp.h>
33
 
#endif
34
 
 
35
 
#include <Foundation/NSObject.h>
36
 
 
37
 
typedef enum {
38
 
  NSRoundDown,
39
 
  NSRoundUp,
40
 
  NSRoundPlain,         /* Round .5 up          */
41
 
  NSRoundBankers        /* Make last digit even */
42
 
} NSRoundingMode;
43
 
 
44
 
typedef enum {
45
 
  NSCalculationNoError = 0,
46
 
  NSCalculationUnderflow,       /* result became zero */
47
 
  NSCalculationOverflow,
48
 
  NSCalculationLossOfPrecision,
49
 
  NSCalculationDivideByZero
50
 
} NSCalculationError;
51
 
 
52
 
/*
53
 
 *      Give a precision of at least 38 decimal digits
54
 
 *      requires 128 bits.
55
 
 */
56
 
#define NSDecimalMaxSize (16/sizeof(mp_limb_t))
57
 
 
58
 
#define NSDecimalMaxDigit 38
59
 
#define NSDecimalNoScale 128
60
 
 
61
 
typedef struct {
62
 
  signed char   exponent;       /* Signed exponent - -128 to 127        */
63
 
  BOOL  isNegative;     /* Is this negative?                    */
64
 
  BOOL  validNumber;    /* Is this a valid number?              */
65
 
#if     HAVE_GMP
66
 
  mp_size_t size;
67
 
  mp_limb_t lMantissa[NSDecimalMaxSize];
68
 
#else
69
 
  unsigned char length;         /* digits in mantissa.                  */
70
 
  unsigned char cMantissa[NSDecimalMaxDigit];
71
 
#endif
72
 
} NSDecimal;
73
 
 
74
 
static inline BOOL
75
 
NSDecimalIsNotANumber(const NSDecimal *decimal)
76
 
{
77
 
  return (decimal->validNumber == NO);
78
 
}
79
 
 
80
 
GS_EXPORT void
81
 
NSDecimalCopy(NSDecimal *destination, const NSDecimal *source);
82
 
 
83
 
GS_EXPORT void
84
 
NSDecimalCompact(NSDecimal *number);
85
 
 
86
 
GS_EXPORT NSComparisonResult
87
 
NSDecimalCompare(const NSDecimal *leftOperand, const NSDecimal *rightOperand);
88
 
 
89
 
GS_EXPORT void
90
 
NSDecimalRound(NSDecimal *result, const NSDecimal *number, int scale, NSRoundingMode mode);
91
 
 
92
 
GS_EXPORT NSCalculationError
93
 
NSDecimalNormalize(NSDecimal *n1, NSDecimal *n2, NSRoundingMode mode);
94
 
 
95
 
GS_EXPORT NSCalculationError
96
 
NSDecimalAdd(NSDecimal *result, const NSDecimal *left, const NSDecimal *right, NSRoundingMode mode);
97
 
 
98
 
GS_EXPORT NSCalculationError
99
 
NSDecimalSubtract(NSDecimal *result, const NSDecimal *left, const NSDecimal *right, NSRoundingMode mode);
100
 
 
101
 
GS_EXPORT NSCalculationError
102
 
NSDecimalMultiply(NSDecimal *result, const NSDecimal *l, const NSDecimal *r, NSRoundingMode mode);
103
 
 
104
 
GS_EXPORT NSCalculationError
105
 
NSDecimalDivide(NSDecimal *result, const NSDecimal *l, const NSDecimal *rr, NSRoundingMode mode);
106
 
    
107
 
GS_EXPORT NSCalculationError
108
 
NSDecimalPower(NSDecimal *result, const NSDecimal *n, unsigned power, NSRoundingMode mode);
109
 
 
110
 
GS_EXPORT NSCalculationError
111
 
NSDecimalMultiplyByPowerOf10(NSDecimal *result, const NSDecimal *n, short power, NSRoundingMode mode);
112
 
 
113
 
GS_EXPORT NSString*
114
 
NSDecimalString(const NSDecimal *decimal, NSDictionary *locale);
115
 
 
116
 
 
117
 
// GNUstep extensions to make the implementation of NSDecimalNumber totaly 
118
 
// independent for NSDecimals internal representation
119
 
 
120
 
// Give back the biggest NSDecimal
121
 
GS_EXPORT void
122
 
NSDecimalMax(NSDecimal *result);
123
 
 
124
 
// Give back the smallest NSDecimal
125
 
GS_EXPORT void
126
 
NSDecimalMin(NSDecimal *result);
127
 
 
128
 
// Give back the value of a NSDecimal as a double
129
 
GS_EXPORT double
130
 
NSDecimalDouble(NSDecimal *number);
131
 
 
132
 
// Create a NSDecimal with a mantissa, exponent and a negative flag
133
 
GS_EXPORT void
134
 
NSDecimalFromComponents(NSDecimal *result, unsigned long long mantissa, 
135
 
                      short exponent, BOOL negative);
136
 
 
137
 
// Create a NSDecimal from a string using the local
138
 
GS_EXPORT void
139
 
NSDecimalFromString(NSDecimal *result, NSString *numberValue, 
140
 
                    NSDictionary *locale);
141
 
 
142
 
#endif
143
 
#endif
144