package mathutil

import 

// IsNumeric returns true if the given character is a numeric, otherwise false.
func ( byte) bool { return  >= '0' &&  <= '9' }

// IsInteger strict check the given value is an integer(intX,uintX), otherwise false.
func ( any) bool {
	switch .(type) {
	case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr:
		return true
	default:
		return false
	}
}

// IsFloat returns true if the given character is a float(32/64), otherwise false.
func ( any) bool {
	switch .(type) {
	case float32, float64:
		return true
	default:
		return false
	}
}

// Compare any intX,floatX value by given op. returns `first op(=,!=,<,<=,>,>=) second`
//
// Usage:
//
//	mathutil.Compare(2, 3, ">") // false
//	mathutil.Compare(2, 1.3, ">") // true
//	mathutil.Compare(2.2, 1.3, ">") // true
//	mathutil.Compare(2.1, 2, ">") // true
func (,  any,  string) bool {
	if  == nil ||  == nil {
		return false
	}

	switch fVal := .(type) {
	case float64:
		if ,  := ToFloat();  == nil {
			return CompFloat(, , )
		}
	case float32:
		if ,  := ToFloat();  == nil {
			return CompFloat(float64(), , )
		}
	default: // as int64
		if ,  := ToInt64();  == nil {
			if ,  := ToInt64();  == nil {
				return CompInt64(, , )
			}
		}
	}

	return false
}

// CompInt compare all intX,uintX type value. returns `first op(=,!=,<,<=,>,>=) second`
func [ comdef.Xint](,  ,  string) ( bool) {
	return CompValue(, , )
}

// CompInt64 compare int64 value. returns `first op(=,!=,<,<=,>,>=) second`
func (,  int64,  string) bool {
	return CompValue(, , )
}

// CompFloat compare float64,float32 value. returns `first op(=,!=,<,<=,>,>=) second`
func [ comdef.Float](,  ,  string) ( bool) {
	return CompValue(, , )
}

// CompValue compare intX,uintX,floatX value. returns `first op(=,!=,<,<=,>,>=) second`
func [ comdef.Number](,  ,  string) ( bool) {
	switch  {
	case "<", "lt":
		 =  < 
	case "<=", "lte":
		 =  <= 
	case ">", "gt":
		 =  > 
	case ">=", "gte":
		 =  >= 
	case "=", "eq":
		 =  == 
	case "!=", "ne", "neq":
		 =  != 
	}
	return
}

// InRange check if val in int/float range [min, max]
func [ comdef.Number](, ,  ) bool {
	return  >=  &&  <= 
}

// OutRange check if val not in int/float range [min, max]
func [ comdef.Number](, ,  ) bool {
	return  <  ||  > 
}

// InUintRange check if val in unit range [min, max]
func [ comdef.Uint](, ,  ) bool {
	if  == 0 {
		return  >= 
	}
	return  >=  &&  <= 
}

// InDelta Check whether two floating-point numbers are equal within a specified margin of error
//
// Params:
//   want - 期望的浮点数值
//   give - 实际给定的浮点数值
//   delta - 允许的误差范围
func [ comdef.Float](,  ,  float64) bool {
	 := float64() - float64()
	if  < 0 {
		 = -
	}
	return  <= 
}

// InDeltaAny Check whether two floating-point numbers are equal within a specified margin of error
func (,  any,  float64) bool {
	,  := ToFloat()
	if  != nil {
		return false
	}
	,  := ToFloat()
	if  != nil {
		return false
	}
	return InDelta(, , )
}