text stringlengths 0 234 |
|---|
when 09 => days_of_previous_months := 243; |
when 10 => days_of_previous_months := 273; |
when 11 => days_of_previous_months := 304; |
when 12 => days_of_previous_months := 334; |
when others => days_of_previous_months := 0; |
end case; |
if m > 2 and then Is_leap (y) then -- February has 29 days in leap years. |
days_of_previous_months := days_of_previous_months + 1; |
end if; |
-- |
y_diff := (y - 1) - 1900; |
y_diff_4 := (y - 1) / 4 - 1900 / 4; |
y_diff_100 := (y - 1) / 100 - 1900 / 100; |
y_diff_400 := (y - 1) / 400 - 1900 / 400; |
-- Add extra days of leap years from 1901 (included) to year y (excluded). |
days_of_previous_years := 365 * y_diff + y_diff_4 - y_diff_100 + y_diff_400; |
-- |
return days_of_previous_years + days_of_previous_months + d - 1; |
end Days_since_1901; |
-- |
sec : constant Day_Duration := Seconds (date); |
begin |
-- With GNAT and perhaps other systems, Duration's range allows the following: |
-- return Long_Float(date - Time_Of(1901, 01, 01, 0.0)) / 86_400.0 + 367.0; |
-- With ObjectAda and perhaps other systems, we need to count days since 1900 ourselves. |
return |
Long_Float (sec) / 86_400.0 + |
Long_Float (Days_since_1901 (Year (date), Month (date), Day (date))) + |
367.0; -- Days from 1899-12-31 to 1901-01-01. |
-- Lotus 1-2-3, then Excel, are based on 1899-12-31 (and believe it is 1900-01-01). |
end To_Number; |
procedure Write(xl: in out Excel_Out_Stream; r,c : Positive; date: Time) |
is |
begin |
Write(xl, r,c, To_Number(date)); |
end Write; |
-- Ada.Text_IO - like. No need to specify row & column each time |
procedure Put(xl: in out Excel_Out_Stream; num : Long_Float) is |
begin |
Write(xl, xl.curr_row, xl.curr_col, num); |
end Put; |
procedure Put(xl : in out Excel_Out_Stream; |
num : in Integer; |
width : in Ada.Text_IO.Field := 0; -- ignored |
base : in Ada.Text_IO.Number_Base := 10 |
) |
is |
begin |
if base = 10 then |
Write(xl, xl.curr_row, xl.curr_col, num); |
else |
declare |
use Ada.Strings.Fixed; |
s: String(1..50 + 0*width); |
-- 0*width is just to skip a warning of width being unused |
package IIO is new Ada.Text_IO.Integer_IO(Integer); |
begin |
IIO.Put(s, num, Base => base); |
Put(xl, Trim(s, Ada.Strings.Left)); |
Function Definition: function Mantissa (Value : Float_64) return Unsigned_64 is |
Function Body: pragma Inline (Mantissa); |
begin |
return |
( Unsigned_64 (Value (8)) |
or Shift_Left (Unsigned_64 (Value (7)), 8 ) |
or Shift_Left (Unsigned_64 (Value (6)), 2*8) |
or Shift_Left (Unsigned_64 (Value (5)), 3*8) |
or Shift_Left (Unsigned_64 (Value (4)), 4*8) |
or Shift_Left (Unsigned_64 (Value (3)), 5*8) |
or Shift_Left (Unsigned_64 (Value (2)) and 16#0F#, 6*8) |
or 2 ** Fraction_Bits |
); |
end Mantissa; |
procedure Normalize |
( Value : Number; |
Mantissa : out Unsigned_64; |
Exponent : out Integer |
) is |
begin |
if Number'Machine_Radix = 2 then |
-- |
-- The machine radix is binary. We can use the hardware |
-- representation attributes in order to get the exponent and |
-- the fraction. |
-- |
Exponent := Number'Exponent (Value) - Mantissa_Bits; |
Mantissa := Unsigned_64 (Number'Scaling (Value, -Exponent)); |
else |
-- |
-- OK, this gets more tricky. The number is normalized to be in |
-- the range 2**53 > X >= 2**52, by multiplying to the powers |
-- of two. Some optimization is made to factor out the powers |
-- 2**(2**n)). Though we do not use powers bigger than 30. |
-- |
declare |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.