pokeemerald/src/math_util.c

87 lines
1.0 KiB
C
Raw Normal View History

2017-10-28 21:58:07 +02:00
#include "global.h"
2020-05-20 20:22:41 +02:00
s16 MathUtil_Mul16(s16 x, s16 y)
2017-10-28 21:58:07 +02:00
{
s32 result;
result = x;
result *= y;
result /= 256;
return result;
}
2020-05-20 20:22:41 +02:00
s16 MathUtil_Mul16Shift(u8 s, s16 x, s16 y)
2017-10-28 21:58:07 +02:00
{
s32 result;
result = x;
result *= y;
result /= (1 << s);
return result;
}
2020-05-20 20:22:41 +02:00
s32 MathUtil_Mul32(s32 x, s32 y)
2017-10-28 21:58:07 +02:00
{
s64 result;
result = x;
result *= y;
result /= 256;
return result;
}
2017-10-28 22:09:31 +02:00
2020-05-20 20:22:41 +02:00
s16 MathUtil_Div16(s16 x, s16 y)
2017-10-28 22:09:31 +02:00
{
if (y == 0)
{
return 0;
}
return (x << 8) / y;
}
2020-05-20 20:22:41 +02:00
s16 MathUtil_Div16Shift(u8 s, s16 x, s16 y)
2017-10-28 22:09:31 +02:00
{
if (y == 0)
{
return 0;
}
return (x << s) / y;
}
2020-05-20 20:22:41 +02:00
s32 MathUtil_Div32(s32 x, s32 y)
2017-10-28 22:09:31 +02:00
{
s64 _x;
if (y == 0)
{
return 0;
}
_x = x;
_x *= 256;
return _x / y;
}
2017-10-28 22:15:36 +02:00
2020-05-20 20:22:41 +02:00
s16 MathUtil_Inv16(s16 y)
2017-10-28 22:15:36 +02:00
{
s32 x;
x = 0x10000;
return x / y;
}
2020-05-20 20:22:41 +02:00
s16 MathUtil_Inv16Shift(u8 s, s16 y)
2017-10-28 22:15:36 +02:00
{
s32 x;
x = 0x100 << s;
return x / y;
}
2020-05-20 20:22:41 +02:00
s32 MathUtil_Inv32(s32 y)
2017-10-28 22:15:36 +02:00
{
s64 x;
x = 0x10000;
return x / y;
}