Skip to content

Commit ce59876

Browse files
ADD: Improve mathsolver
1 parent 8818172 commit ce59876

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

data_control/umathsolver.pas

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(******************************************************************************)
22
(* umathsolver.pas ??.??.???? *)
33
(* *)
4-
(* Version : 0.08 *)
4+
(* Version : 0.09 *)
55
(* *)
66
(* Author : Uwe Schächterle (Corpsman) *)
77
(* *)
@@ -31,6 +31,7 @@
3131
(* 0.06 - =, <> *)
3232
(* 0.07 - Formatieren von Binärzahlen Nibble weise *)
3333
(* 0.08 - trunc, floor repariert *)
34+
(* 0.09 - a^b für a < 0 und b ganzzahlig *)
3435
(* *)
3536
(******************************************************************************)
3637

@@ -540,15 +541,58 @@
540541

541542
Function Pow_Float(v1, v2: Pointer): Pointer;
542543
Var
544+
tmp, tmp2: mp_float;
545+
tmpi: mp_int;
543546
res: pmp_float;
544547
Begin
548+
(*
549+
* Für a^b gibt es verschiendene Fälle
550+
*
551+
* a > 0: res := a^b;
552+
*
553+
* a = 0: res := 0;
554+
*
555+
* a < 0:
556+
* if ganzzahlig(b) then begin
557+
* if b mod 2 = 0 then begin
558+
* res := abs(a)^b;
559+
* end else begin
560+
* res := -(abs(a)^b);
561+
* end;
562+
* end else begin
563+
* res := 0;
564+
* end;
565+
*
566+
*)
545567
new(res);
546568
mpf_init(res^);
547-
If (s_mpf_is_ge0(pmp_float(v1)^) And (Not s_mpf_is0(pmp_float(v1)^))) Then Begin
548-
mpf_expt(pmp_float(v1)^, pmp_float(v2)^, res^);
569+
If s_mpf_is0(pmp_float(v1)^) Then Begin
570+
mpf_set0(res^);
549571
End
550572
Else Begin
551-
mpf_set0(res^);
573+
If s_mpf_is_ge0(pmp_float(v1)^) Then Begin
574+
mpf_expt(pmp_float(v1)^, pmp_float(v2)^, res^);
575+
End
576+
Else Begin
577+
mpf_init(tmp2);
578+
mpf_int(pmp_float(v2)^, tmp2);
579+
If mpf_is_eq(pmp_float(v2)^, tmp2) Then Begin
580+
mpf_init(tmp);
581+
mpf_abs(pmp_float(v1)^, tmp);
582+
mpf_expt(tmp, pmp_float(v2)^, res^);
583+
mp_init(tmpi);
584+
mpf_trunc(tmp2, tmpi);
585+
If mp_isodd(tmpi) Then Begin
586+
mpf_chs(res^, res^);
587+
End;
588+
mp_clear(tmpi);
589+
mpf_clear(tmp);
590+
End
591+
Else Begin
592+
mpf_set0(res^);
593+
End;
594+
mpf_clear(tmp2);
595+
End;
552596
End;
553597
result := res;
554598
End;

0 commit comments

Comments
 (0)