Files
pmomusic/upnp/statevariables/utils_numeric_operandes.go

33 lines
786 B
Go
Raw Normal View History

2025-07-13 07:02:26 +02:00
package statevariables
2025-07-12 12:28:13 +02:00
import "fmt"
2025-07-12 21:23:39 +02:00
// valuesToNumericOperands takes two interface{} values, casts them to a numeric type based on a given StateVarType, and returns their float64 equivalents.
// If any error occurs during casting or conversion to float64, it is returned along with zero values for the operands.
2025-07-12 12:28:13 +02:00
func valuesToNumericOperands(t StateVarType, a interface{}, b interface{}) (float64, float64, error) {
var err error
if !t.IsNumeric() {
return 0, 0, fmt.Errorf("type %v is not numeric", t)
}
a, err = t.Cast(a)
if err != nil {
return 0, 0, err
}
b, err = t.Cast(b)
if err != nil {
return 0, 0, err
}
af, err := toFloat(a, 64)
if err != nil {
return 0, 0, err
}
bf, err := toFloat(b, 64)
if err != nil {
return 0, 0, err
}
return af, bf, nil
}