386trig.inc
来自「开放源码的编译器open watcom 1.6.0版的源代码」· INC 代码 · 共 426 行 · 第 1/2 页
INC
426 行
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
;;#include <stdio.h>
;;#include <math.h>
;;#include <limits.h>
;;#include <errno.h>
;;
;;PIby4:
;; dt 0.785398163397448309615
;;
;;extern double _EvalPoly( double, double *, int );
;;extern double _OddPoly( double, double *, int );
;;
;;
;;static double _sinpoly[] = {
;; 1.0 / (2.*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17),
;; -1.0 / (2.*3*4*5*6*7*8*9*10*11*12*13*14*15),
;; 1.0 / (2.*3*4*5*6*7*8*9*10*11*12*13),
;; -1.0 / (2.*3*4*5*6*7*8*9*10*11),
;; 1.0 / (2.*3*4*5*6*7*8*9),
;; -1.0 / (2.*3*4*5*6*7),
;; 1.0 / (2.*3*4*5),
;; -1.0 / (2.*3),
;; 1.0
;;};
;;__sinpoly:
;; dt 0.0000000000000028114572543455207631 ; 1./17!
;; dt -0.00000000000076471637318198164759 ; 1./15!
;; dt 0.00000000016059043836821614599 ; 1./13!
;; dt -0.000000025052108385441718775 ; 1./11!
;; dt 0.0000027557319223985890652 ; 1./9!
;; dt -0.00019841269841269841269 ; 1./7!
;; dt 0.0083333333333333333333 ; 1./5!
;; dt -0.16666666666666666666 ; 1./3!
;; dt 1.00000000000000000000 ; 1./1!
;;
;;static double _cospoly[] = {
;; 1.0 / (2.*3*4*5*6*7*8*9*10*11*12*13*14*15*16),
;; -1.0 / (2.*3*4*5*6*7*8*9*10*11*12*13*14),
;; 1.0 / (2.*3*4*5*6*7*8*9*10*11*12),
;; -1.0 / (2.*3*4*5*6*7*8*9*10),
;; 1.0 / (2.*3*4*5*6*7*8),
;; -1.0 / (2.*3*4*5*6),
;; 1.0 / (2.*3*4),
;; -1.0 / (2.),
;; 1.0
;;};
;;__cospoly:
;; dt 0.000000000000047794773323873852974 ; 1./16!
;; dt -0.000000000011470745597729724713 ; 1./14!
;; dt 0.0000000020876756987868098979 ; 1./12!
;; dt -0.00000027557319223985890652 ; 1./10!
;; dt 0.000024801587301587301587 ; 1./8!
;; dt -0.0013888888888888888888 ; 1./6!
;; dt 0.041666666666666666666 ; 1./4!
;; dt -0.50000000000000000000 ; 1./2!
;;_One:
;; dt 1.00000000000000000000 ; 1./1!
Degree label word
dw 0, 1, 2, 3, 4, 4, 5, 5, 6
;;
cosy equ -12
exponent equ cosy-4
iflag equ exponent-4
index equ iflag-4
;;
;;void _sincos( long double *x, int flag )
;; {
;; int i;
;; long j;
;; auto int exponent;
;; auto int index;
;; double y;
;; double siny, cosy;
;; double sinx, cosx;
;; static char *func_name[] = { "sin", "tan", "cos" };
defp __sincos
push EBP ; save EBP
push EDI ; save registers
push EDX ; ...
push ECX ; ...
push EBX ; ...
mov EBP,ESP ; point to stack
sub ESP,12 ; allocate temporaries
;;
;; frexp( x, &exponent );
;; if( exponent >= 32 ) {
;; return( _matherr( TLOSS, func_name[flag], &x, &x, 0.0 ) );
;; }
mov EDI,EAX ; save address of argument
sub ECX,ECX ; zero ECX
mov CX,8[EAX] ; get exponent
and CX,7FFFh ; ...
sub CX,3FFEh ; ...
cmp CX,32 ; if exponent too large
_if ge ; then
; error
_endif ; endif
push ECX ; save exponent
;; y = __fprem( x, PIby4, &i ); /* 24-nov-88 */
push ESI ; save quadrant
push EDI ; save address of operand
mov SI,8[EAX] ; get exponent of op1
mov DI,PIBY4_EXP ; get pi/4
mov ECX,PI_HW ; ...
mov EBX,PI_LW ; ...
mov EDX,4[EAX] ; get operand
mov EAX,[EAX] ; ...
call ___fprem ; calc remainder
pop ECX ; restore address of operand
mov [ECX],EAX ; store the remainder
mov 4[ECX],EDX ; ...
mov 8[ECX],SI ; ...
mov EAX,EDI ; store quotient
mov EDI,ECX ; get address of operand
pop ESI ; restore quadrant
;; if( y < 0.0 ) { ; 03-may-90
;; y += PIby4;
;; --i;
;; }
test byte ptr 9[EDI],80h ; if y < 0.0
_if ne ; then
push EAX ; - save i
mov EBX,EDI ; - y = y + PIby4
mov EAX,EDI ; - ...
push PIBY4_EXP ; - push pi/4
push PI_HW ; - ...
push PI_LW ; - ...
call __FLDAC ; - y = y + pi/4
pop EAX ; - restore i
dec EAX ; - i = i - 1
_endif ; endif
;; i = (i + (flag & 2)) & 7;
mov EBX,ESI ; get flag
mov AH,BL ; save it
and BL,2 ; ...
add AL,BL ; + i
and AL,7 ; & 7
push EAX ; save i and flag
;; if( i & 1 ) { /* if odd octant */
;; y = PIby4 - y;
;; }
test AL,1 ; if odd octant
_if ne ; then calc. y = pi/4 - y
push 8000h+PIBY4_EXP ; - (-pi/4)
push PI_HW ; - ...
push PI_LW ; - ...
mov EAX,EDI ; - y
mov EBX,EDI ; - y
call __FLDAC ; - calc. y = y + -pi/4
xor byte ptr 9[EBX],80h ; - flip the sign bit
_endif ; endif
;; frexp( y, &index );
sub ECX,ECX ; zero whole register
mov CX,8[EDI] ; get exponent
sub CX,3FFEh ; ...
;;/* if( z < ldexp( 1.0, -26 ) ) { */
;;// if( z < 1.49011611938476580e-008 ) {
;; if( index < -26 ) {
;; siny = y;
;; cosy = 1.0;
;; } else {
cmp CX,-32 ; if exponent too small
_if l ; then
mov dword ptr cosy[EBP],ONE_LW ; - set cosy = 1.0
mov dword ptr cosy+4[EBP],ONE_HW
mov word ptr cosy+8[EBP],ONE_EXP
jmp __endif1
_endif ; else
;; if( index > 0 ) index = 0;
;; index = - index;
;; if( index > 8 ) index = 8;
;; index = Degree[ index ];
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?