浏览代码

* SinCos overloads added, resolves #22663

git-svn-id: trunk@22139 -
florian 13 年之前
父节点
当前提交
1da4c0c3ce
共有 4 个文件被更改,包括 70 次插入3 次删除
  1. 1 0
      .gitattributes
  2. 21 1
      rtl/i386/mathu.inc
  3. 31 2
      rtl/objpas/math.pp
  4. 17 0
      tests/test/units/math/tsincos.pp

+ 1 - 0
.gitattributes

@@ -11442,6 +11442,7 @@ tests/test/units/math/tmask.pp svneol=native#text/plain
 tests/test/units/math/tmask2.pp svneol=native#text/plain
 tests/test/units/math/tnaninf.pp svneol=native#text/plain
 tests/test/units/math/tpower.pp svneol=native#text/pascal
+tests/test/units/math/tsincos.pp svneol=native#text/pascal
 tests/test/units/math/ttrig1.pp svneol=native#text/plain
 tests/test/units/matrix/tinv1.pp svneol=native#text/pascal
 tests/test/units/objects/testobj.pp svneol=native#text/plain

+ 21 - 1
rtl/i386/mathu.inc

@@ -24,7 +24,7 @@ function arctan2(y,x : float) : float;assembler;
 
 
 {$define FPC_MATH_HAS_SINCOS}
-procedure sincos(theta : float;out sinus,cosinus : float);assembler;
+procedure sincos(theta : extended;out sinus,cosinus : extended);assembler;
   asm
     fldt theta
     fsincos
@@ -34,6 +34,26 @@ procedure sincos(theta : float;out sinus,cosinus : float);assembler;
   end;
 
 
+procedure sincos(theta : double;out sinus,cosinus : double);assembler;
+  asm
+    fldl theta
+    fsincos
+    fstpl (%edx)
+    fstpl (%eax)
+    fwait
+  end;
+
+
+procedure sincos(theta : single;out sinus,cosinus : single);assembler;
+  asm
+    flds theta
+    fsincos
+    fstps (%edx)
+    fstps (%eax)
+    fwait
+  end;
+
+
 {$define FPC_MATH_HAS_TAN}
 function tan(x : float) : float;assembler;
   asm

+ 31 - 2
rtl/objpas/math.pp

@@ -256,7 +256,16 @@ function radtocycle(rad : float) : float;inline;
 function tan(x : float) : float;
 function cotan(x : float) : float;
 function cot(x : float) : float; inline;
-procedure sincos(theta : float;out sinus,cosinus : float);
+{$ifdef FPC_HAS_TYPE_SINGLE}
+procedure sincos(theta : single;out sinus,cosinus : single);
+{$endif}
+{$ifdef FPC_HAS_TYPE_DOUBLE}
+procedure sincos(theta : double;out sinus,cosinus : double);
+{$endif}
+{$ifdef FPC_HAS_TYPE_EXTENDED}
+procedure sincos(theta : extended;out sinus,cosinus : extended);
+{$endif}
+
 
 function secant(x : float) : float; inline;
 function cosecant(x : float) : float; inline;
@@ -682,11 +691,31 @@ end;
 
 
 {$ifndef FPC_MATH_HAS_SINCOS}
-procedure sincos(theta : float;out sinus,cosinus : float);
+{$ifdef FPC_HAS_TYPE_SINGLE}
+procedure sincos(theta : single;out sinus,cosinus : single);
   begin
     sinus:=sin(theta);
     cosinus:=cos(theta);
   end;
+{$endif}
+
+
+{$ifdef FPC_HAS_TYPE_DOUBLE}
+procedure sincos(theta : double;out sinus,cosinus : double);
+  begin
+    sinus:=sin(theta);
+    cosinus:=cos(theta);
+  end;
+{$endif}
+
+
+{$ifdef FPC_HAS_TYPE_EXTENDED}
+procedure sincos(theta : extended;out sinus,cosinus : extended);
+  begin
+    sinus:=sin(theta);
+    cosinus:=cos(theta);
+  end;
+{$endif}
 {$endif FPC_MATH_HAS_SINCOS}
 
 

+ 17 - 0
tests/test/units/math/tsincos.pp

@@ -0,0 +1,17 @@
+uses
+  math;
+var
+  s1,s2 : single;
+  d1,d2 : double;
+  e1,e2 : extended;
+
+begin
+  sincos(0,s1,s2);
+  sincos(0,d1,d2);
+  sincos(0,e1,e2);
+  if not(SameValue(s1,0)) or not(SameValue(s2,1)) or not(SameValue(d1,0)) or
+    not(SameValue(d2,1)) or not(SameValue(e1,0)) or not(SameValue(e2,1)) then
+    halt(1);
+  writeln('ok');
+end.
+