/*---------------------------------------------------------------------------* Project: Horizon File: math_Misccellaneous.h Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 12449 $ *---------------------------------------------------------------------------*/ #ifndef NN_MATH_MATH_MISCCELLANEOUS_H_ #define NN_MATH_MATH_MISCCELLANEOUS_H_ #include #ifdef __cplusplus namespace nn { namespace math { }} // nn::math #endif // __cplusplus // C declarations follow #include NN_EXTERN_C inline s64 nnmathMultiplyAndDivide(s64 x, s32 mul, s32 div) { // Note right shift // Compiler dependent const s64 rate = ((s64)(mul) << 32) / div; const s32 r_hi = (s32)(rate >> 32); const u32 r_lo = (u32)(rate >> 0); const s32 x_hi = (s32)(x >> 32); const u32 x_lo = (u32)(x >> 0); return (((s64)(x_hi) * r_hi) << 32) + ( (s64)(x_hi) * r_lo + (s64)(r_hi) * x_lo ) + (((u64)(x_lo) * r_lo) >> 32); } #endif // NN_MATH_MATH_MISCCELLANEOUS_H_