mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 12:39:24 +02:00
* bugfix for int64 to float conversion
This commit is contained in:
parent
87d0fb3cda
commit
c0a2149c38
@ -4597,51 +4597,47 @@ End;
|
||||
| to the double-precision floating-point format. The conversion is performed
|
||||
| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic.
|
||||
*----------------------------------------------------------------------------*}
|
||||
|
||||
function int64_to_float64( a: int64 ): float64;
|
||||
var
|
||||
zSign : flag;
|
||||
float_result : float64;
|
||||
intval : int64rec;
|
||||
AbsA : bits64;
|
||||
shiftcount : int8;
|
||||
zSig0, zSig1 : bits32;
|
||||
Begin
|
||||
if ( a = 0 ) then
|
||||
begin
|
||||
int64_to_float64.low := 0;
|
||||
int64_to_float64.high := 0;
|
||||
exit;
|
||||
Begin
|
||||
packFloat64( 0, 0, 0, 0, float_result );
|
||||
exit;
|
||||
end;
|
||||
if ( a = sbits64 ( 1 shl 64 ) ) then
|
||||
begin
|
||||
packFloat64(1, $43E, 0, 0, float_result);
|
||||
int64_to_float64 := float_result;
|
||||
exit;
|
||||
end;
|
||||
if a < 0 then
|
||||
zSign := flag(TRUE)
|
||||
zSign := flag( a < 0 );
|
||||
if ZSign<>0 then
|
||||
AbsA := -a
|
||||
else
|
||||
zSign := flag(FALSE);
|
||||
if zSign<>0 then
|
||||
a := -a;
|
||||
if zSign <> 0 then
|
||||
begin
|
||||
a:=-a;
|
||||
intval.low := int64rec(a).low;
|
||||
intval.high := int64rec(a).high;
|
||||
normalizeRoundAndPackFloat64( zSign, $43C, intval.low, intval.high , float_result )
|
||||
end
|
||||
AbsA := a;
|
||||
shiftCount := countLeadingZeros64( absA ) - 11;
|
||||
if ( 0 <= shiftCount ) then
|
||||
Begin
|
||||
absA := absA shl shiftcount;
|
||||
zSig0:=int64rec(absA).high;
|
||||
zSig1:=int64rec(absA).low;
|
||||
End
|
||||
else
|
||||
begin
|
||||
intval.low := int64rec(a).low;
|
||||
intval.high := int64rec(a).high;
|
||||
normalizeRoundAndPackFloat64( zSign, $43C, intval.low, intval.high , float_result );
|
||||
end;
|
||||
Begin
|
||||
shift64Right( absA, 0, - shiftCount, zSig0, zSig1 );
|
||||
End;
|
||||
packFloat64( zSign, $432 - shiftCount, zSig0, zSig1, float_result );
|
||||
int64_to_float64:= float_result;
|
||||
End;
|
||||
|
||||
end.
|
||||
{
|
||||
$Log$
|
||||
Revision 1.3 2002-10-12 20:24:22 carl
|
||||
Revision 1.4 2002-10-13 15:47:39 carl
|
||||
* bugfix for int64 to float conversion
|
||||
|
||||
Revision 1.3 2002/10/12 20:24:22 carl
|
||||
+ int64_tof_loat conversion routines
|
||||
|
||||
Revision 1.2 2002/10/08 20:07:08 carl
|
||||
|
Loading…
Reference in New Issue
Block a user