// Generated by EML-lang Go backend
// Source module: aerospace_actuator_guard_band
// Kernel digest: sha256:0b0ef5a5baecb59acc7d28dc64bc959d9f3378cfbc278204c737cef5bc755aaa
// Functions:     1
// Constants:     0

package aerospaceactuatorguardband

import (
	"math"
)

// eml_builtin_max: NaN when either argument is NaN. math.Max(+Inf, NaN) is +Inf.
func eml_builtin_max(a float64, b float64) float64 {
	if math.IsNaN(a) {
		return a
	}
	if math.IsNaN(b) {
		return b
	}
	return math.Max(a, b)
}

// eml_builtin_min: NaN when either argument is NaN. math.Min(-Inf, NaN) is -Inf.
func eml_builtin_min(a float64, b float64) float64 {
	if math.IsNaN(a) {
		return a
	}
	if math.IsNaN(b) {
		return b
	}
	return math.Min(a, b)
}

// actuator_command_within_band -- compiled from EML-lang.
// Pfaffian profile: pfaffian_r=0, cost_class=p0-d4-w0-c0, drift_risk=LOW.
// requires: (u_min <= u_max)
// ensures:  (u_min <= result)
// ensures:  (result <= u_max)
//  source obligations for actuator_command_within_band: {O1, O2}
//    O1 [43d7c3ff9568] -> PRESERVED (equivalent)  panic before return; Go has no build flag that removes a panic
//         build: unconditional -- panic; Go has no flag that removes it
//    O2 [ca2e303109b7] -> PRESERVED (equivalent)  panic before return; Go has no build flag that removes a panic
//         build: unconditional -- panic; Go has no flag that removes it
// @verify lean theorem=actuator_command_within_band
func actuator_command_within_band(error float64, integral float64, deriv float64, kp float64, ki float64, kd float64, u_min float64, u_max float64) float64 {
	if !((u_min <= u_max)) { panic("actuator_command_within_band: requires (u_min <= u_max)") }
	result := eml_builtin_max(u_min, eml_builtin_min(((float64((kp * error)) + float64((ki * integral))) + float64((kd * deriv))), u_max))
	if !((u_min <= result)) { panic("actuator_command_within_band: ensures violated: (u_min <= result)") }
	if !((result <= u_max)) { panic("actuator_command_within_band: ensures violated: (result <= u_max)") }
	return result
}
