// Copyright 1999-2000 Omni Development, Inc.  All rights reserved.
//
// This software may only be used and reproduced according to the
// terms in the file OmniSourceLicense.html, which should be
// distributed with this project and can also be found at
// http://www.omnigroup.com/DeveloperResources/OmniSourceLicense.html.

#import <OmniFoundation/NSDecimalNumber-OFExtensions.h>

#import <Foundation/Foundation.h>
#import <OmniBase/OmniBase.h>

RCS_ID("$Header: /Network/Source/CVS/OmniGroup/Frameworks/OmniFoundation/OpenStepExtensions.subproj/NSDecimalNumber-OFExtensions.m,v 1.4 2000/01/19 23:35:25 kc Exp $")

@implementation NSDecimalNumber (OFExtensions)

- (NSDecimalNumber *)decimalNumberByConvertingFromAnnualizedPercentageRateToMonthlyRate;
{
    return [self decimalNumberByDividingBy:(NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInt:1200]];
}

- (NSDecimalNumber *)decimalNumberByConvertingFromMonthlyRateToAnnualizedPercentageRate;
{
    return [self decimalNumberByMultiplyingBy:(NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInt:1200]];
}

- (NSDecimalNumber *)decimalNumberByRoundingToScale:(short)scale roundingMode:(NSRoundingMode)roundingMode;
{
    NSDecimal decimalToRound;
    NSDecimal result;

    decimalToRound = [self decimalValue];
    NSDecimalRound(&result, &decimalToRound, scale, roundingMode);

    return [NSDecimalNumber decimalNumberWithDecimal:result];
}

- (NSDecimalNumber *)decimalNumberByRoundingToScale:(short)scale withFactor:(NSDecimalNumber *)factor roundingMode:(NSRoundingMode)roundingMode;
{
    NSDecimalNumber *numberToRound;
    NSDecimalNumber *roundedNumber;

    numberToRound = [self decimalNumberByMultiplyingBy:factor];
    roundedNumber = [numberToRound decimalNumberByRoundingToScale:scale roundingMode:roundingMode];

    return [roundedNumber decimalNumberByDividingBy:factor];
}

+ (BOOL)decimalNumberIsEqualToZero:(NSDecimalNumber *)decimalNumber;
{
    return [decimalNumber compare:[NSDecimalNumber zero]] == NSOrderedSame;
}

+ (BOOL)decimalNumberIsNotEqualToZero:(NSDecimalNumber *)decimalNumber;
{
    return [decimalNumber compare:[NSDecimalNumber zero]] != NSOrderedSame;
}

+ (BOOL)decimalNumberIsGreaterThanZero:(NSDecimalNumber *)decimalNumber;
{
    return [decimalNumber compare:[NSDecimalNumber zero]] == NSOrderedDescending;
}

+ (BOOL)decimalNumberIsGreaterThanOrEqualToZero:(NSDecimalNumber *)decimalNumber;
{
    return [decimalNumber compare:[NSDecimalNumber zero]] != NSOrderedAscending;
}

+ (BOOL)numberIsLessThanZero:(NSDecimalNumber *)decimalNumber;
{
    return [decimalNumber compare:[NSDecimalNumber zero]] == NSOrderedAscending;
}

- (BOOL)isGreaterThanDecimalNumber:(NSDecimalNumber *)aDecimalNumber;
{
    return [self compare:aDecimalNumber] == NSOrderedDescending;
}

@end
