with BitsAKD; with MemoAKD; with TypeAKD; use TypeAKD; package body StriAKD is --------------------------------------------------------------------------- --------------------------------------------------------------------------- -- Copyright (C) 1994 David Wallace Croft. All rights reserved. -- String manipulation. -- Use InStr'last instead of Length(InStr). --------------------------------------------------------------------------- --------------------------------------------------------------------------- procedure Float_Binary ( Item : in float; Sign : out character; Exponent : out integer; Significand : out Boolean_Array ) is --------------------------------------------------------------------------- use BitsAKD; B : Array_Byte ( 0..7 ); Exp : Word_Type; Sig : long_integer; S : Boolean_Array ( Significand'range ); S_Index : natural range 0..S'last; begin if Item = 0.0 then Sign := ' '; Exponent := 0; Significand := ( others => false ); return; end if; for Offset in reverse B'range loop B ( Offset ) := MemoAKD.Peek ( MemoAKD.Address ( long_integer ( Item'address ) + long_integer ( Offset ) ) ); end loop; if Bits_Are_Set ( B ( B'last ), Bit7 ) then Sign := '-'; else Sign := '+'; end if; Exp := Set_Byte ( 0 , High, B ( B'last ) ); Exp := Set_Byte ( Exp, Low , B ( B'last - 1 ) ); Exp := Clear_Bits ( Exp, Bit15 + Bit3 + Bit2 + Bit1 + Bit0 ); Exp := Shift_Bits ( Exp, Right, 4 ); Exp := Exp - ( 2**10 - 1 ); Exponent := Exp; Sig := long_integer ( B ( B'last - 1 ) ); Sig := long_integer ( Clear_Bits ( Word_Type ( Sig ), Bit7 + Bit6 + Bit5 ) ); S_Index := 0; for index in reverse 0..4 loop S_Index := S_Index + 1; S ( S_Index ) := Bits_Are_Set ( B ( B'last - 1 ), 2**index ); end loop; for Byte_Index in reverse B'first..( B'last - 2 ) loop for Bit_Index in reverse 0..7 loop S_Index := S_Index + 1; S ( S_Index ) := Bits_Are_Set ( B ( Byte_Index ), 2**Bit_Index ); end loop; end loop; if Exp >= 0 then if Exp mod 2 = 1 then Sig := 2 ** Exp; else Sig := 0; end if; for index in 1..Exp+1 loop if S ( index ) then Sig := Sig + 2 ** ( Exp + 1 - index ); end if; end loop; end if; Significand := S; Significand ( 1 ) := true; end Float_Binary; --------------------------------------------------------------------------- --------------------------------------------------------------------------- end StriAKD;