1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-16 04:25:23 +00:00
OpenDiablo2/OpenDiablo2/Math.go

32 lines
578 B
Go
Raw Normal View History

2019-10-24 13:31:59 +00:00
package OpenDiablo2
// Min returns the lower of two values
func Min(a, b uint32) uint32 {
if a < b {
return a
}
return b
}
// Max returns the higher of two values
func Max(a, b uint32) uint32 {
if a > b {
return a
}
return b
}
// Max returns the higher of two values
func MaxInt32(a, b int32) int32 {
if a > b {
return a
}
return b
}
// BytesToInt32 converts 4 bytes to int32
func BytesToInt32(b []byte) int32 {
// equivalnt of return int32(binary.LittleEndian.Uint32(b))
return int32(uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24)
}