1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: math_Misccellaneous.h
4
5 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Rev: 12449 $
14 *---------------------------------------------------------------------------*/
15
16 #ifndef NN_MATH_MATH_MISCCELLANEOUS_H_
17 #define NN_MATH_MATH_MISCCELLANEOUS_H_
18
19 #include <nn/types.h>
20
21 #ifdef __cplusplus
22
23 namespace nn { namespace math {
24 }} // nn::math
25
26 #endif // __cplusplus
27
28 // 以下、C 用宣言
29
30 #include <nn/util/detail/util_CLibImpl.h>
31
nnmathMultiplyAndDivide(s64 x,s32 mul,s32 div)32 NN_EXTERN_C inline s64 nnmathMultiplyAndDivide(s64 x, s32 mul, s32 div)
33 {
34 // 右シフト注意
35 // コンパイラ依存
36 const s64 rate = ((s64)(mul) << 32) / div;
37 const s32 r_hi = (s32)(rate >> 32);
38 const u32 r_lo = (u32)(rate >> 0);
39 const s32 x_hi = (s32)(x >> 32);
40 const u32 x_lo = (u32)(x >> 0);
41
42 return (((s64)(x_hi) * r_hi) << 32)
43 + ( (s64)(x_hi) * r_lo
44 + (s64)(r_hi) * x_lo )
45 + (((u64)(x_lo) * r_lo) >> 32);
46 }
47
48 #endif // NN_MATH_MATH_MISCCELLANEOUS_H_
49