/usr/include/GNUstep/Foundation/NSDecimalNumber.h is in libgnustep-base-dev 1.22.1-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | /* Interface of NSDecimalNumber class
Copyright (C) 1998 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Created: November 1998
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#ifndef __NSDecimalNumber_h_GNUSTEP_BASE_INCLUDE
#define __NSDecimalNumber_h_GNUSTEP_BASE_INCLUDE
#import <GNUstepBase/GSVersionMacros.h>
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
#import <Foundation/NSObject.h>
#import <Foundation/NSDecimal.h>
#import <Foundation/NSValue.h>
#if defined(__cplusplus)
extern "C" {
#endif
@class NSDecimalNumber;
/**
* This protocol encapsulates information about how an [NSDecimalNumber]
* should round and process exceptions. Usually you can just create objects
* of the [NSDecimalNumberHandler] class, which implements this protocol, but
* if you don't want to use that class you can create your own implementing
* it.
*/
@protocol NSDecimalNumberBehaviors
/**
* <p>Specifies behavior when, in the course of applying method to leftOperand
* and rightOperand, an [NSDecimalNumber] instance encounters given error.</p>
* <p>error has four possible constant values:</p>
* <deflist>
* <term><code>NSCalculationLossOfPrecision</code></term>
* <desc>The number can't be represented in 38 significant digits.</desc>
* <term><code>NSCalculationOverflow</code></term>
* <desc>The number is too large to represent.</desc>
* <term><code>NSCalculationUnderflow</code></term>
* <desc>The number is too small to represent.</desc>
* <term><code>NSCalculationDivideByZero</code></term>
* <desc>The caller tried to divide by 0.</desc>
* </deflist>
*
* <p>Behavior on error can be one of the following:</p>
* <list>
* <item>Raise an exception.</item>
* <item>Return nil. The calling method will return its value as though no
* error had occurred. If error is
* <code>NSCalculationLossOfPrecision</code>, method will return an
* imprecise value, constrained to 38 significant digits. If error is
* <code>NSCalculationUnderflow</code> or
* <code>NSCalculationOverflow</code>, method will return
* <code>NSDecimalNumber</code>'s <code>notANumber</code>. You shouldn't
* return nil if error is <code>NSDivideByZero</code>.
* </item>
* <item>Correct the error and return a valid <code>NSDecimalNumber</code>.
* The calling method will use this as its own return value.</item>
* </list>
*/
- (NSDecimalNumber*) exceptionDuringOperation: (SEL)method
error: (NSCalculationError)error
leftOperand: (NSDecimalNumber*)leftOperand
rightOperand: (NSDecimalNumber*)rightOperand;
/**
* Specifies how [NSDecimalNumber]'s <code>decimalNumberBy...</code> methods
* round their return values. This should be set to one of the following
* constants:
* <deflist>
* <term><code>NSRoundDown</code></term>
* <desc>Always round down.</desc>
* <term><code>NSRoundUp</code></term>
* <desc>Always round up.</desc>
* <term><code>NSRoundPlain</code></term>
* <desc>Round to the closest possible return value. Halfway (e.g. .5)
* rounds up for positive numbers, down for negative (towards larger absolute
* value).</desc>
* <term><code>NSRoundBankers</code></term>
* <desc>Round to the closest possible return value, but halfway (e.g. .5)
* rounds towards possibility whose last digit is even.</desc>
* </deflist>
*/
- (NSRoundingMode) roundingMode;
/**
* Specifies the precision of the values returned by [NSDecimalNumber]'s
* <code>decimalNumberBy...</code> methods, in terms of the number of
* digits allowed after the decimal point. This can be negative, implying
* that the precision should be, e.g., 100's, 1000's, etc.. For unlimited
* precision, set to <code>NSDecimalNoScale</code>.
*/
- (short) scale;
@end
/**
* A utility class adopting [(NSDecimalNumberBehaviors)] protocol. Can be used
* to control [NSDecimalNumber] rounding and exception-handling behavior, by
* passing an instance as an argument to any [NSDecimalNumber] method ending
* with <code>...Behavior:</code>.
*/
@interface NSDecimalNumberHandler : NSObject <NSDecimalNumberBehaviors>
{
#if GS_EXPOSE(NSDecimalNumberHandler)
NSRoundingMode _roundingMode;
short _scale;
BOOL _raiseOnExactness;
BOOL _raiseOnOverflow;
BOOL _raiseOnUnderflow;
BOOL _raiseOnDivideByZero;
#endif
#if GS_NONFRAGILE
#else
/* Pointer to private additional data used to avoid breaking ABI
* when we don't have the non-fragile ABI available.
* Use this mechanism rather than changing the instance variable
* layout (see Source/GSInternal.h for details).
*/
@private id _internal GS_UNUSED_IVAR;
#endif
}
/**
* Provides an instance implementing the default behavior for the
* [NSDecimalNumber] class. 38 decimal digits, rounded to closest return
* value (<code>NSRoundPlain</code>). Exceptions raised on overflow,
* underflow, and divide by zero.
*/
+ (id)defaultDecimalNumberHandler;
/**
* Constructor setting all behavior. (For more precise control over error
* handling, create your own class implementing the [(NSDecimalNumberBehaviors)]
* protocol.)
*/
+ (id)decimalNumberHandlerWithRoundingMode:(NSRoundingMode)roundingMode
scale:(short)scale
raiseOnExactness:(BOOL)raiseOnExactness
raiseOnOverflow:(BOOL)raiseOnOverflow
raiseOnUnderflow:(BOOL)raiseOnUnderflow
raiseOnDivideByZero:(BOOL)raiseOnDivideByZero;
/**
* Initializer setting all behavior. (For more precise control over error
* handling, create your own class implementing the [(NSDecimalNumberBehaviors)]
* protocol.)
*/
- (id)initWithRoundingMode:(NSRoundingMode)roundingMode
scale:(short)scale
raiseOnExactness:(BOOL)raiseOnExactness
raiseOnOverflow:(BOOL)raiseOnOverflow
raiseOnUnderflow:(BOOL)raiseOnUnderflow
raiseOnDivideByZero:(BOOL)raiseOnDivideByZero;
@end
/**
* <p>Class that implements a number of methods for performing decimal
* arithmetic to arbitrary precision. The behavior in terms of rounding
* choices and exception handling may be customized using the
* [NSDecimalNumberHandler] class, and defaults to
* [NSDecimalNumberHandler+defaultDecimalNumberHandler].</p>
*
* <p>Equivalent functionality to the <code>NSDecimalNumber</code> class may
* be accessed through functions, mostly named <code>NSDecimalXXX</code>,
* e.g., NSDecimalMin(). Both the class and the functions use a structure
* called <code>NSDecimal</code>.</p>
*
* <p>Note that instances of <code>NSDecimalNumber</code> are immutable.</p>
*/
@interface NSDecimalNumber : NSNumber <NSDecimalNumberBehaviors>
{
#if GS_EXPOSE(NSDecimalNumber)
NSDecimal data;
#endif
}
/**
* Returns the default rounding/precision/exception handling behavior, which
* is same as [NSDecimalNumberHandler+defaultDecimalNumberHandler] unless it
* has been explicitly set otherwise.
*/
+ (id <NSDecimalNumberBehaviors>)defaultBehavior;
/**
* Sets the default rounding/precision/exception handling behavior to the
* given behavior. If this is not called, behavior defaults to
* [NSDecimalNumberHandler+defaultDecimalNumberHandler].
*/
+ (void)setDefaultBehavior:(id <NSDecimalNumberBehaviors>)behavior;
/**
* Return maximum positive value that can be represented.
*/
+ (NSDecimalNumber *)maximumDecimalNumber;
/**
* Return minimum negative value (<em>not</em> the smallest positive value)
* that can be represented.
*/
+ (NSDecimalNumber *)minimumDecimalNumber;
/**
* Return a fixed value representing an NaN.
*/
+ (NSDecimalNumber *)notANumber;
/**
* Return a constant object with a value of one.
*/
+ (NSDecimalNumber *)one;
/**
* Return a constant object with a value of zero.
*/
+ (NSDecimalNumber *)zero;
/**
* New instance with given value. Note an NSDecimal may be created using the
* function NSDecimalFromString().
*/
+ (NSDecimalNumber *)decimalNumberWithDecimal:(NSDecimal)decimal;
/**
* New instance by component. Note that the precision of this initializer is
* limited.
*/
+ (NSDecimalNumber *)decimalNumberWithMantissa:(unsigned long long)mantissa
exponent:(short)exponent
isNegative:(BOOL)isNegative;
/**
* New instance from string. Arbitrary precision is preserved, though calling
* one of the <code>decimalNumberBy...</code> methods will return a result
* constrained by the current <em><code>scale</code></em>. Number format
* is parsed according to current default locale.
*/
+ (NSDecimalNumber *)decimalNumberWithString:(NSString *)numericString;
/**
* New instance from string. Arbitrary precision is preserved, though calling
* one of the <code>decimalNumberBy...</code> methods will return a result
* constrained by the current <em><code>scale</code></em>. Number format
* is parsed according to given locale.
*/
+ (NSDecimalNumber *)decimalNumberWithString:(NSString *)numericString
locale:(NSDictionary *)locale;
/**
* Initialize with given value. Note an NSDecimal may be created using the
* function NSDecimalFromString().
*/
- (id)initWithDecimal:(NSDecimal)decimal;
/**
* Initialize by component. Note that the precision of this initializer is
* limited.
*/
- (id)initWithMantissa:(unsigned long long)mantissa
exponent:(short)exponent
isNegative:(BOOL)flag;
/**
* Initialize from string. Arbitrary precision is preserved, though calling
* one of the <code>decimalNumberBy...</code> methods will return a result
* constrained by the current <em><code>scale</code></em>. Number format
* is parsed according to current default locale.
*/
- (id)initWithString:(NSString *)numberValue;
/**
* Initialize from string. Arbitrary precision is preserved, though calling
* one of the <code>decimalNumberBy...</code> methods will return a result
* constrained by the current <em><code>scale</code></em>. Number format
* is parsed according to given locale.
*/
- (id)initWithString:(NSString *)numberValue
locale:(NSDictionary *)locale;
/**
* Returns the Objective-C type (<code>@encode(...)</code> compatible) of the
* data contained <code>NSDecimalNumber</code>, which is by convention "d"
* (for double), even though this is not strictly accurate.
*/
- (const char *)objCType;
/**
* Return underlying value as an <code>NSDecimal</code> structure.
*/
- (NSDecimal)decimalValue;
/**
* Returns string version of number formatted according to locale.
*/
- (NSString *)descriptionWithLocale:(id)locale;
/**
* Returns underlying value as a <code>double</code>, which may be an
* approximation if precision greater than the default of 38.
*/
- (double)doubleValue;
/**
* Compares with other number, returning less, greater, or equal.
*/
- (NSComparisonResult)compare:(NSNumber *)decimalNumber;
/**
* Adds self to decimalNumber and returns new result, using +defaultBehavior
* for rounding/precision/error handling.
*/
- (NSDecimalNumber *)decimalNumberByAdding:(NSDecimalNumber *)decimalNumber;
/**
* Adds self to decimalNumber and returns new result, using given behavior
* for rounding/precision/error handling.
*/
- (NSDecimalNumber *)decimalNumberByAdding:(NSDecimalNumber *)decimalNumber
withBehavior:(id<NSDecimalNumberBehaviors>)behavior;
/**
* Divides self by decimalNumber and returns new result, using +defaultBehavior
* for rounding/precision/error handling.
*/
- (NSDecimalNumber *)decimalNumberByDividingBy:(NSDecimalNumber *)decimalNumber;
/**
* Divides self by decimalNumber and returns new result, using given behavior
* for rounding/precision/error handling.
*/
- (NSDecimalNumber *)decimalNumberByDividingBy:(NSDecimalNumber *)decimalNumber
withBehavior:(id <NSDecimalNumberBehaviors>)behavior;
/**
* Multiplies self by decimalNumber and returns new result, using
* +defaultBehavior for rounding/precision/error handling.
*/
- (NSDecimalNumber *)decimalNumberByMultiplyingBy:(NSDecimalNumber *)decimalNumber;
/**
* Multiplies self by decimalNumber and returns new result, using given
* behavior for rounding/precision/error handling.
*/
- (NSDecimalNumber *)decimalNumberByMultiplyingBy:(NSDecimalNumber *)decimalNumber
withBehavior:(id <NSDecimalNumberBehaviors>)behavior;
/**
* Multiplies self by given power of 10 and returns new result, using
* +defaultBehavior for rounding/precision/error handling.
*/
- (NSDecimalNumber *)decimalNumberByMultiplyingByPowerOf10:(short)power;
/**
* Multiplies self by given power of 10 and returns new result, using given
* behavior for rounding/precision/error handling.
*/
- (NSDecimalNumber *)decimalNumberByMultiplyingByPowerOf10:(short)power
withBehavior:(id <NSDecimalNumberBehaviors>)behavior;
/**
* Raises self to given positive integer power and returns new result, using
* +defaultBehavior for rounding/precision/error handling.
*/
- (NSDecimalNumber *)decimalNumberByRaisingToPower:(NSUInteger)power;
/**
* Raises self to given positive integer power and returns new result, using
* given behavior for rounding/precision/error handling.
*/
- (NSDecimalNumber *)decimalNumberByRaisingToPower:(NSUInteger)power
withBehavior:(id <NSDecimalNumberBehaviors>)behavior;
/**
* Subtracts decimalNumber from self and returns new result, using
* +defaultBehavior for rounding/precision/error handling.
*/
- (NSDecimalNumber *)decimalNumberBySubtracting:
(NSDecimalNumber *)decimalNumber;
/**
* Subtracts decimalNumber from self and returns new result, using given
* behavior for rounding/precision/error handling.
*/
- (NSDecimalNumber *)decimalNumberBySubtracting:
(NSDecimalNumber *)decimalNumber
withBehavior:(id <NSDecimalNumberBehaviors>)behavior;
/**
* Returns rounded version of underlying decimal.
*/
- (NSDecimalNumber *)decimalNumberByRoundingAccordingToBehavior:(id <NSDecimalNumberBehaviors>)behavior;
@end
/**
* Interface for obtaining an NSDecimalNumber value from an ordinary
* NSNumber.
*/
@interface NSNumber (NSDecimalNumber)
/**
* Obtaining an NSDecimalNumber version of an ordinary NSNumber.
*/
- (NSDecimal) decimalValue;
@end
#if defined(__cplusplus)
}
#endif
#endif
#endif
|