with System.Machine_Code; use System.Machine_Code; package body Ada.Numerics.Aux is NL : constant String := ASCII.LF & ASCII.HT; function Exp (X : Double) return Double is Result : Double; begin Asm (Template => "fldl2e " & NL & "fmulp %%st, %%st(1)" & NL -- X * log2 (E) & "fld %%st(0) " & NL & "frndint " & NL -- Integer (X * Log2 (E)) & "fsubr %%st, %%st(1)" & NL -- Fraction (X * Log2 (E)) & "fxch " & NL & "f2xm1 " & NL -- 2**(...) - 1 & "fld1 " & NL & "faddp %%st, %%st(1)" & NL -- 2**(Fraction (X * Log2 (E))) & "fscale " & NL -- E ** X & "fstp %%st(1) ", Outputs => Double'Asm_Output ("=t", Result), Inputs => Double'Asm_Input ("0", X)); return Result; end Exp; function Tanh (X : Double) return Double is begin if abs X > 23.0 then return Double'Copy_Sign (1.0, X); end if; return 1.0 / (1.0 + Exp (-(2.0 * X))) - 1.0 / (1.0 + Exp (2.0 * X)); end Tanh; end Ada.Numerics.Aux;