diff options
Diffstat (limited to 'gcc/ada/libgnat/a-calend.adb')
-rw-r--r-- | gcc/ada/libgnat/a-calend.adb | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/gcc/ada/libgnat/a-calend.adb b/gcc/ada/libgnat/a-calend.adb index 4f89a40..0be5673 100644 --- a/gcc/ada/libgnat/a-calend.adb +++ b/gcc/ada/libgnat/a-calend.adb @@ -1068,19 +1068,28 @@ is tv_nsec : out Long_Integer) is pragma Unsuppress (Overflow_Check); - Secs : Duration; - Nano_Secs : Duration; begin - -- Seconds extraction, avoid potential rounding errors - - Secs := D - 0.5; - tv_sec := Long_Long_Integer (Secs); - - -- Nanoseconds extraction + if D = 0.0 then + tv_sec := 0; + tv_nsec := 0; + + elsif D < 0.0 then + tv_sec := Long_Long_Integer (D + 0.5); + if D = Duration (tv_sec) then + tv_nsec := 0; + else + tv_nsec := Long_Integer ((D - Duration (tv_sec)) * Nano + 0.5); + end if; - Nano_Secs := D - Duration (tv_sec); - tv_nsec := Long_Integer (Nano_Secs * Nano); + else + tv_sec := Long_Long_Integer (D - 0.5); + if D = Duration (tv_sec) then + tv_nsec := 0; + else + tv_nsec := Long_Integer ((D - Duration (tv_sec)) * Nano - 0.5); + end if; + end if; end To_Struct_Timespec_64; ------------------ |