separate ( Generic_Elementary_Functions ) function Log ( X : Float_Type ) return Float_Type is -- On input, X is a floating-point value in Float_Type; -- on output, the value of log(X) (natural log of X) is returned. -- The bulk of the computations are performed by the procedure -- KP_Log( Y, M, Z1, Z2 ) which returns log(Y) in M, Z1, and Z2 -- where -- log(Y) = M * log2 + Z1 + Z2, -- M of integer value, and Z1 only has at most 12 significant bits. Y, M, Z1, Z2, Result : Common_Float; Log2_Lead : constant Common_Float := 16#0.B17#; Log2_Trail : constant Common_Float := 16#0.000217F7D1CF79ABC9E3B39803F2F6AF40#; begin Y := Common_Float( X ); if ( Y = 0.0 ) then raise Constraint_Error; end if; if ( Y < 0.0 ) then raise Argument_Error; end if; -- Get values of M, Z1, and Z2 so that the natural log of X -- can be calculated by log(X) = M*log(2) + Z1 + Z2 KP_Log ( Y, M, Z1, Z2 ); if ( M = 0.0 ) then Result := Z1 + Z2; else Result := M*Log2_Trail + Z2; Result := (M*Log2_Lead + Z1) + Result; end if; return( Float_Type(Result) ); end Log;