summaryrefslogtreecommitdiff
path: root/gmpextras.pas
blob: ebb7d17e6eac40456c26b624069762ba2289dbec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
unit gmpextras;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, gmp;

function mpfToStr(f: mpf_t): string;
function mpfMyRoot(rad: mpf_t; wzlExp: int64): extended;

implementation

uses
  math;

// allgemeine Funktionen *******************************************************

function mpfToStr(f: mpf_t): string;
var
  ex:  mp_exp_t;
  off: byte;
begin
  result:=mpf_get_str(nil,ex,10,0,f);
  off:=1+byte(pos('-',result)=1);
  if result='' then
    result:='0'
  else if ex=1 then
    result:=copy(result,1,off)+','+copy(result,off+1,length(result)-off)
  else
    result:=copy(result,1,off)+','+copy(result,off+1,length(result)-off)+' * 10^'+intToStr(ex-1);
end;

function mpfMyRoot(rad: mpf_t; wzlExp: int64): extended;
var
  ex: mp_exp_t;
begin
  result:=power(mpf_get_d_2exp(ex,rad),1/wzlExp);
  result:=result*power(2,ex/wzlExp);
end;

end.