-- Generated by EML-lang Ada/SPARK backend (body)
-- Source module: aerospace_actuator_guard_band
-- Kernel digest: sha256:0b0ef5a5baecb59acc7d28dc64bc959d9f3378cfbc278204c737cef5bc755aaa
-- Functions:     1
-- Constants:     0

-- REQUIRED BUILD FLAG: -ffp-contract=off  (and it is required even with -ffast-math)
--   GNAT contracts `A + B * C` into one fused multiply-add at -O1 and above (GCC's default for
--   every language but ISO C), which changes this artifact's last bits. EML's `A + B * C` is an
--   add of a ROUNDED product; the fused operation is written `fma (A, B, C)` in the source.
--   Unlike C, C++ and Go, Ada has NO source-level control over this: measured on GNAT 13.3.0,
--   `pragma Machine_Attribute (F, "optimize", "fp-contract=off")` is ignored with a warning,
--   `Long_Float'Machine (B * C)` is a no-op, and a `constant Long_Float` temporary does not stop
--   it. Pass -ffp-contract=off (gnatmake ... -cargs -ffp-contract=off) or build at -O0.
--   On the targets that CAN state this in their own text (C, C++, Go), the rule deliberately
--   overrides -ffast-math: a kernel's last bits must not move because of an ambient CFLAG.
--   Pass -ffp-contract=off here for the same reason, whatever else your build asks for; write
--   `fma (A, B, C)` in the source where you want the fused operation.

pragma SPARK_Mode (On);

with Ada.Numerics.Long_Elementary_Functions;
use  Ada.Numerics.Long_Elementary_Functions;

package body AerospaceActuatorGuardBand is

   function actuator_command_within_band
   (error : Long_Float; integral : Long_Float; deriv : Long_Float; kp : Long_Float; ki : Long_Float; kd : Long_Float; u_min : Long_Float; u_max : Long_Float) return Long_Float is
   begin
      return Eml_Builtin_Max (u_min, Eml_Builtin_Min ((((kp * error) + (ki * integral)) + (kd * deriv)), u_max));
   end actuator_command_within_band;

end AerospaceActuatorGuardBand;
