#include "IOFixed64.h"
IOFixed64 operator* (const IOFixed64 a, const IOFixed64 b)
{
IOFixed64 result(a);
result *= b;
return result;
}
IOFixed64 operator* (const IOFixed64 a, const SInt64 b)
{
IOFixed64 result(a);
result *= b;
return result;
}
IOFixed64 operator/ (const IOFixed64 a, const IOFixed64 b)
{
IOFixed64 result(a);
result /= b;
return result;
}
IOFixed64 operator/ (const IOFixed64 a, const SInt64 b)
{
IOFixed64 result(a);
result /= b;
return result;
}
IOFixed64 operator+ (const IOFixed64 a, const IOFixed64 b)
{
IOFixed64 result(a);
result += b;
return result;
}
IOFixed64 operator+ (const IOFixed64 a, const SInt64 b)
{
IOFixed64 result(a);
result += b;
return result;
}
IOFixed64 operator- (const IOFixed64 a, const IOFixed64 b)
{
IOFixed64 result(a);
result -= b;
return result;
}
IOFixed64 operator- (const IOFixed64 a, const SInt64 b)
{
IOFixed64 result(a);
result -= b;
return result;
}
IOFixed64 exponent(const IOFixed64 original, const UInt8 power)
{
IOFixed64 result;
if (power) {
int i;
result = original;
for (i = 1; i < power; i++) {
result *= original;
}
}
return result;
}
UInt32 llsqrt(UInt64 x)
{
UInt64 rem = 0;
UInt64 root = 0;
int i;
for (i = 0; i < 32; i++) {
root <<= 1;
rem = ((rem << 2) + (x >> 62));
x <<= 2;
root++;
if (root <= rem) {
rem -= root;
root++;
} else {
root--;
}
}
return(UInt32)(root >> 1);
}
UInt16 lsqrt(UInt32 x)
{
UInt32 rem = 0;
UInt32 root = 0;
int i;
for (i = 0; i < 16; i++) {
root <<= 1;
rem = ((rem << 2) + (x >> 30));
x <<= 2;
root++;
if (root <= rem) {
rem -= root;
root++;
} else {
root--;
}
}
return(UInt16)(root >> 1);
}
IOFixed64 IOQuarticFunction( const IOFixed64 x, const IOFixed64 *gains )
{
IOFixed64 function_at_x = x * gains[0] + exponent(x * gains[1], 2);
if( gains[2] != 0LL )
function_at_x += exponent(x * gains[2], 3);
if( gains[3] != 0LL )
function_at_x += exponent(x * gains[3], 4);
return function_at_x;
}
IOFixed64 IOQuarticDerivative( const IOFixed64 x, const IOFixed64 *gains )
{
IOFixed64 derivative_at_x = gains[0] + x * exponent(gains[1], 2) * 2LL;
if( gains[2] != 0LL )
derivative_at_x += exponent(x, 2) * exponent(gains[2], 3) * 3LL;
if( gains[3] != 0LL )
derivative_at_x += exponent(x, 3) * exponent(gains[3], 4) * 4LL;
return derivative_at_x;
}