/*
    MathArrayPrivate - Handles mathematical operations on arrays of numbers
    
    private definitions for MathArray.
    
    Copyright (C) 1995, Adam Fedor
    
    $Id: MathArrayPrivate.h,v 1.8 1996/04/03 16:20:44 adam Exp $
*/

#ifndef __MathArrayPrivate_INCLUDE
#define __MathArrayPrivate_INCLUDE

#include "MathArray/MaskedException.h"
#include "MathArray/MathArray.h"
#include "MathArray/NSObjectExtra.h"

/* Get some information from the precision */
#define MATH_SIGNED(prec)		(prec & 0x0f00)

/* Set to non-zero for some types of math errors */
extern int ma_fpe_errno;

/* Random seed */
extern int ma_random_seed;

/* Convenient functions for determining the size of the arrays */
extern unsigned long array_sizeof_elements(const char *type);
extern unsigned long array_aligned_sizeof_elements(const char *type);
extern unsigned long array_num_elements(unsigned dimensions, 
	const unsigned* size);
extern unsigned long array_num_bytes(unsigned dimensions, const unsigned* size,
	const char *type);

/* Convienent functions for stepping through the array */
extern ordered_index_t ordered_index(unsigned dimension, NSData* size, 
		unsigned *index);
extern ordered_index_t inverted_ordered_index(unsigned dimension, NSData* size, 
		unsigned *index);
extern unsigned* start_index_from_range(unsigned dimension, NSRange *range,
		unsigned *buf);
extern int increment_index_in_range(unsigned dimension, 
		NSRange *range, unsigned *index, unsigned step);

/* Standard Exceptions */
#define MA_RAISE_FPE	\
	[MaskedException raise:MAFloatingPointException \
		format:@"A floating point error occured during a mathematical computation"];
#define MA_RAISE_PARAMETER	\
	[NSException raise:MAParameterException \
		format:@"The specified data doesn't match the specified parameters"];
#define MA_RAISE_ARRAY_MISMATCH	\
	[NSException raise:MAArrayMismatchException \
		format:@"The size of the given arrays do no match"];
#define MA_RAISE_RANGE	\
	[NSException raise:MARangeException \
		format:@"The specified range exceeds the array limits"];
#define MA_RAISE_CAST	\
	[NSException raise:MACastException \
		format:@"Cannot cast to the required type for the operation"];
#define MA_RAISE_PERFORM	\
	[NSException raise:MAPerformException \
		format:@"Cannot perform the specified operation on data"];

#define MA_RAISE_ILLEGAL	\
	[NSException raise:MAPerformException \
		format:@"Illegal operation on this type of data."];

#define MA_RAISE_MALLOC \
        [NSException raise:NSMallocException \
            format:@"No memory left to allocate"]; \

#define MA_CHECK_MALLOC(ptr) \
        if (!ptr) {MA_RAISE_MALLOC}


@interface MathArray (Private)
+ (Class)classForObjCType:(const char *)theType;
- (void)_updateLazyArray;
+ (void)_startMath;
+ (void)_finishMath;
@end

#ifdef NEXT_FOUNDATION
static NSRange
NSMakeRange (float location, float length)
{
  NSRange range;
  range.location = location;
  range.length = length;
  return range;
}
#endif

#endif /* __MathArrayPrivate_INCLUDE */
