2
0

ufloat128.pp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2007 by the FPC development time
  4. Implements overloaded operators and misc. functions to
  5. provide a float128 type
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$inline on}
  13. {$IFNDEF FPC_DOTTEDUNITS}
  14. unit ufloat128;
  15. {$ENDIF FPC_DOTTEDUNITS}
  16. interface
  17. {$IFDEF FPC_DOTTEDUNITS}
  18. uses
  19. System.SoftFpu128;
  20. {$ELSE FPC_DOTTEDUNITS}
  21. uses
  22. sfpu128;
  23. {$ENDIF FPC_DOTTEDUNITS}
  24. type
  25. float128 = {$IFDEF FPC_DOTTEDUNITS}System.SoftFpu128{$ELSE}sfpu128{$ENDIF}.float128;
  26. operator+ (const f1,f2 : float128) result : float128;inline;
  27. operator* (const f1,f2 : float128) result : float128;inline;
  28. operator- (const f1,f2 : float128) result : float128;inline;
  29. operator/ (const f1,f2 : float128) result : float128;inline;
  30. operator :=(const source : double) dest : float128;inline;
  31. operator :=(const source : float128) dest : double;inline;
  32. procedure DumpFloat128(const f : float128);
  33. implementation
  34. procedure DumpFloat128(const f : float128);
  35. type
  36. ta = packed array[0..SizeOf(float128)-1] of byte;
  37. var
  38. i : longint;
  39. begin
  40. for i:=SizeOf(float128)-1 downto 0 do
  41. begin
  42. write(hexstr(ta(f)[i],2));
  43. if i<15 then
  44. write(' ');
  45. end;
  46. end;
  47. operator+ (const f1,f2 : float128) result : float128;inline;
  48. begin
  49. result:=float128_add(f1,f2);
  50. end;
  51. operator* (const f1,f2 : float128) result : float128;inline;
  52. begin
  53. result:=float128_mul(f1,f2);
  54. end;
  55. operator- (const f1,f2 : float128) result : float128;inline;
  56. begin
  57. result:=float128_sub(f1,f2);
  58. end;
  59. operator/ (const f1,f2 : float128) result : float128;inline;
  60. begin
  61. result:=float128_div(f1,f2);
  62. end;
  63. operator :=(const source : double) dest : float128;inline;
  64. begin
  65. dest:=float64_to_float128(float64(source));
  66. end;
  67. operator :=(const source : float128) dest : double;inline;
  68. begin
  69. dest:=double(float128_to_float64(source));
  70. end;
  71. end.