Скачиваний:
10
Добавлен:
01.05.2014
Размер:
15.04 Кб
Скачать
‡ ¤ ­ЁҐ ­  « Ў®а в®а­го а Ў®вг N9 Ї® ¤ЁбжЁЇ«Ё­Ґ
"ЋаЈ ­Ё§ жЁп Ё дг­ЄжЁ®­Ёа®ў ­ЁҐ  ЇЇ а в­ле Ё
Їа®Ја ¬¬­ле б।бвў ќ‚Њ"

’Ґ¬ : €§г祭ЁҐ Їа®Ја ¬¬Ёа®ў ­Ёп ¬ вҐ¬ вЁзҐбЄ®Ј®
б®Їа®жҐбб®а  i80•87.


ђ §а Ў®в вм Ї®¤Їа®Ја ¬¬г ­  п§лЄҐ ЂбᥬЎ«Ґа , ®ЎҐбЇҐзЁў ойго
ўлзЁб«Ґ­ЁҐ § ¤ ­­®© ¬ вҐ¬ вЁзҐбЄ®© дг­ЄжЁЁ б ЁбЇ®«м§®ў ­ЁҐ¬ ¬ вҐ-
¬ вЁзҐбЄ®Ј® б®Їа®жҐбб®а . Џ®¤Їа®Ја ¬¬  ¤®«¦­  ўл§лў вмбп Ё§ Ј®-
«®ў­®© Їа®Ја ¬¬л, а §а Ў®в ­­®© ­  п§лЄҐ ‘. ЏаЁ н⮬ ¤®«¦­л Ўлвм
®ЎҐбЇҐзҐ­л § ¤ ­­л© бЇ®б®Ў ўл§®ў  Ё ®Ў¬Ґ­ Ї а ¬Ґва ¬Ё.
Ђ«мвҐа­ вЁў­л© ў аЁ ­в ॠ«Ё§ жЁЁ: а §а Ў®в вм ­  п§лЄҐ Ђб-
ᥬЎ«Ґа  да Ј¬Ґ­в Їа®Ја ¬¬л, ®ЎҐбЇҐзЁў ойЁ© ўлзЁб«Ґ­ЁҐ § ¤ ­­®©
¬ вҐ¬ вЁзҐбЄ®© дг­ЄжЁЁ б ЁбЇ®«м§®ў ­ЁҐ¬ ¬ вҐ¬ вЁзҐбЄ®Ј® б®Їа®жҐб-
б®а , Є®в®ал© ўЄ«оз Ґвбп Ї® ЇаЁ­жЁЇг in-line ў Їа®Ја ¬¬г, а §а -
Ў®в ­­го ­  п§лЄҐ ‘.
‚®§¬®¦­л© ЇаЁ¬Ґа вॡ㥬®© а §а Ў®вЄЁ Їа®Ја ¬¬л ¤«п б«гз п
ўлзЁб«Ґ­Ёп дг­ЄжЁЁ fmod(x,y)=x mod y ЇаЁўҐ¤Ґ­ ­Ё¦Ґ ў ЇаЁ«®¦Ґ­ЁЁ 1.

‚лЇ®«­Ёвм ва ­б«пжЁо Їа®Ја ¬¬л б Ї®¤Ј®в®ўЄ®© ҐҐ  бᥬЎ«Ґа­®©
ўҐабЁЁ Ё ®в« ¤®з­®© Ё­д®а¬ жЁЁ. „«п ўлЎа ­­®Ј® Є®­ва®«м­®Ј® ­ Ў®-
а  Ёб室­ле ¤ ­­ле Їа®Ј­ вм Їа®Ја ¬¬г Ї®¤ гЇа ў«Ґ­ЁҐ¬ ®в« ¤зЁЄ 
td. ЏаЁ н⮬ ¤«п Є ¦¤®© Є®¬ ­¤л б®Їа®жҐбб®а  б«Ґ¤гҐв дЁЄбЁа®ў вм
ᮤҐа¦Ё¬®Ґ ЁбЇ®«м§гҐ¬ле п祥Є Ї ¬пвЁ, ॣЁбва®ў –Џ Ё зЁб«Ґ­­ле
ॣЁбва®ў б®Їа®жҐбб®а  ¤® Ё Ї®б«Ґ ўлЇ®«­Ґ­Ёп нв®© Є®¬ ­¤л.
Џа®ўҐаЁвм Є®а४⭮бвм ўлЇ®«­Ґ­Ёп ўлзЁб«Ґ­Ё© ¤«п ­ҐбЄ®«мЄЁе
­ Ў®а®ў Ёб室­ле ¤ ­­ле.



‚ Ђ ђ € Ђ Ќ ’ › ‡ Ђ „ Ђ Ќ € ‰


‚Ђђ€ЂЌ’ 1.

/*------------------------------------------------------------------------
* filename - hypot.cas
*
* function(s)
* hypot - calculates hypotenuse of right angle
*-----------------------------------------------------------------------*/

/*--------------------------------------------------------------------------*

Name hypot - calculates hypotenuse of right angle

Usage double hypot(double x, double y);

Prototype in math.h

Description hypot calculates the value z where
z^2 = x^2 + y^2

This is equivalent to the length of the hypotenuse of a
right triangle, if the lengths of the two sides are x and y.

Return value hypot returns sqrt (x^2 + y^2);
On error (such as an overflow), hypot returns the value
HUGE_VAL, and sets errno to
ERANGE Value out of range

*---------------------------------------------------------------------------*/


‚Ђђ€ЂЌ’ 2.

/*------------------------------------------------------------------------
* filename - poly.cas
*
* function(s)
* poly - generates a polynomial from arguments
*-----------------------------------------------------------------------*/

Name poly - generates a polynomial from arguments

Usage double poly(double x, int n, double c []);

Prototype in math.h

Description poly generates a polynomial in x, of degree n, with
coefficients c[0], c[1], ..., c[n]. For example, if n=4,
the generated polynomial is

c[4].x^4 + c[3].x^3 + c[2].x^2] + c[1].x + c[0]

The polynomial is calculated using Horner's method:

polynom = (..((x.c[n] + c[n-1]).x + c[n-2])..).x + c[0]

Return value poly returns the value of the polynomial as evaluated for
the given x.
If n < 0 then the result is a domain error.
A range error occurs if the result exceeds double range.

*---------------------------------------------------------------------------*/


‚Ђђ€ЂЌ’ 3.

/*------------------------------------------------------------------------
* filename - cosh.cas
*
* function(s)
/*------------------------------------------------------------------------

Name cosh - hyperbolic function:
cosh (x) = (exp(x) + exp(-x)) / 2

Usage double cosh(double x);

Prototype in math.h

Description cosh computes the hyperbolic cosine of the input value.

Return value cosh returns the hyperbolic cosine of the input value.
For large arguments (magnitude greater than or equal to
710.475) the result will be HUGE_VAL of the appropriate
sign and errno will be set to:
ERANGE Range error.

cosh is more accurately calculated by the polynomial

(1 + x^2/2)

when x is tiny (|x| < 2^-13).
*---------------------------------------------------------------------------*/


‚Ђђ€ЂЌ’ 4.

/*------------------------------------------------------------------------
* filename - sinh.cas
*
* function(s)
* sinh - hyperbolic sine function
*-----------------------------------------------------------------------*/

Name sinh - hyperbolic sine function

Usage double sinh(double x);

Prototype in math.h

Description sinh computes the hyperbolic sine of the input value.

Return value sinh returns the hyperbolic sine of the input value.
For large arguments (magnitude greater than or equal to
710.475) the result will be an EDOM error.

*---------------------------------------------------------------------------*/

/*
Algorithm.

The usual formula is:
sinh(x) = .5*(exp(x) - exp(-x))
but there is a loss of precision in using this formula directly near 0.

Since sinh(-x) = -sinh(x), compute sinh(|x|) and adjust the sign later.

If 0 <= x < 2^-33, return x.

If x >= 710.475 call matherr.

If x >= .3465, use
y = exp(x)
sinh(x) = (y - 1/y)/2

If 2^-33 <= x < .3465, use
y = exp(x) - 1
sinh(x) = (y + y/(1 + y))/2
where special chip functions are used to get exp(x)-1 accurately.

*/


‚Ђђ€ЂЌ’ 5.

/*------------------------------------------------------------------------
* filename - tanh.cas
*
* function(s)
* tanh - hyperbolic tangent function
*-----------------------------------------------------------------------*/

Name tanh - hyperbolic tangent function

Usage double tanh(double x);

Prototype in math.h

Description tanh calculates the hyperbolic tangent of the input.

Return value tanh returns the hyperbolic tangent of the input value.
For large arguments (magnitude greater than 32) the result
will be +1.0 or -1.0.

*---------------------------------------------------------------------------*/

/*
Algorithm.

The usual formula is:
tanh(x) = (exp(x) - exp(-x))/(exp(x) + exp(-x))/
but there is a loss of precision in using this formula directly near 0.

Since tanh(-x) = -tanh(x), compute tanh(|x|) and adjust the sign later.

If 0 <= x < 2^-33, return x.

If x >= 32 return 1.

If x >= .17325, use
y = exp(x)
tanh(x) = (y - 1/y)/(y + 1/y)

If 2^-33 <= x < .17325, use
y = exp(2x) - 1
sinh(x) = y/(2 + y)
where special chip functions are used to get exp(2x)-1 accurately.

*/


‚Ђђ€ЂЌ’ 6.

/*------------------------------------------------------------------------
* filename - ldexp.cas
*
* function(s)
* ldexp - calculates value * 2^exp
*-----------------------------------------------------------------------*/

Name ldexp - calculates value * 2^exp

Usage double ldexp(double value, int exp);

Prototype in math.h

Description ldexp calculates value * 2^exp

Return value ldexp returns value * 2^exp
Overflows return HUGE_VAL * sign(value), underflows return 0.0,
in both cases with errno set to ERANGE.

*---------------------------------------------------------------------------*/


‚Ђђ€ЂЌ’ 7.

/*------------------------------------------------------------------------
* filename - acosasin.cas
*
* function(s)
* AcosAsin - compute acos or asin
* acos - trigonometric function
* asin - trigonometric function
*-----------------------------------------------------------------------*/

typedef unsigned short bits16;

*---------------------------------------------------------------------*/
Name AcosAsin - compute sin or cos

Usage double AcosAsin (char *whoS, bits16 flags, double *xP);

Prototype in math.h

Description Computes acos or asin of the number pointed to by xP.
Arguments to asin and acos must be in the range -1 to 1.
Arguments outside that range will cause asin or acos
to return 0 and set errno to:
EDOM Domain error

Return value Returns acos or asin of xP.
acos returns a value in the range 0 to pi.
asin returns a value in the range -pi/2 to pi/2.

*---------------------------------------------------------------------*/

static double near AcosAsin (char *whoS, bits16 flags, double *xP)
{
volatile bits16 status;
/*
„«п ўлзЁб«Ґ­Ёп Acos : return AcosAsin ("acos", 0xFF, &x);
„«п ўлзЁб«Ґ­Ёп Asin : return AcosAsin ("asin", 0x00, &x);
/*

/*
Use the trig identities: asin (x) = atan (x / sqrt (1 - x^2)) ;
acos (x) = atan (sqrt (1-x^2) / x), which is
the inverse of the tangent ratio used for asin (x).
*/



‚Ђђ€ЂЌ’ 8.

/*------------------------------------------------------------------------
* filename - modf.cas
*
* function(s)
* modf - splits into mantissa and exponent
*-----------------------------------------------------------------------*/

Name modf - splits into mantissa and exponent

Usage double modf(double value, double *wholeP);

Prototype in math.h

Description modf breaks the double value into two parts: the integer
and the fraction. It stores the integer in wholeP and
returns the fraction.

Return value modf returns the fractional part of value.

*---------------------------------------------------------------------------*/



‚Ђђ€ЂЌ’ 9.

/*------------------------------------------------------------------------
* filename - frexp.cas
*
* function(s)
* frexp - splits a double number into mantissa and exponent
*-----------------------------------------------------------------------*/

/*--------------------------------------------------------------------------*

Name frexp - splits a double number into mantissa and exponent

Usage double frexp(double value, int *expP);

Prototype in math.h

Description Split a floating point number into its exponent and
fractional parts, with the exponent placed into *expP, and
the fraction is the function return value.

Return value frexp returns value - (*expP = chop (value));

*---------------------------------------------------------------------------*/


‚Ђђ€ЂЌ’ 10.

/*------------------------------------------------------------------------
* filename - atan2.cas
*
* function(s)
*
*-----------------------------------------------------------------------*/

Name atan2 - trigonometric function

Usage double atan2(double y, double x);

Prototype in math.h

Description atan2 returns the arc tangent of y/x and will produce
correct results even when resulting is near pi/2 or -pi/2
(x near 0).

Return value atan2 returns a value in the range -pi to pi.
If a ratio of 0/0 is supplied then _RANGE_VAL is returned
and errno is set to:
EDOM Domain error

Caution: atan2(+0,-1) = +pi but atan2(-0,-1) = -pi.

*---------------------------------------------------------------------------*/



_________________________________________________________________________




Џ ђ € ‹ Ћ † … Ќ € … 1.


/*------------------------------------------------------------------------
* filename - fmod.cas
* function(s)
* fmod - ўлзЁб«пҐв x Ї® ¬®¤г«о y, ®бв в®Є ®в x/y
*-----------------------------------------------------------------------*/

#pragma inline
#include <asmrules.h>
#include <_math.h>
#include <math.h>

/*--------------------------------------------------------------------------*

€¬п fmod - ўлзЁб«пҐв x Ї® ¬®¤г«о y, ®бв в®Є ®в x/y

€бЇ®«м§®ў ­ЁҐ double fmod(double x, double y);

Џа®в®вЁЇ ў... math.h

ЋЇЁб ­ЁҐ fmod ўлзЁб«пҐв x - (y * int(x / y));
ќв  а §­®бвм ¬®¦Ґв Ўлвм ўлзЁб«Ґ­  Ў®«ҐҐ в®з­® б
ЁбЇ®«м§®ў ­ЁҐ¬ Є®¬ ­¤л FPREM, Ї®ўв®апо饩бп ў жЁЄ«Ґ.
Ќ ЇаЁ¬Ґа:

while (not finished) result = fprem (x, y)

Ќ® нв® Ўг¤Ґв ¬Ґ¤«Ґ­­ҐҐ, Ґб«Ё ®в­®иҐ­ЁҐ x/y ўҐ«ЁЄ®.

‚®§ўа й Ґ¬®Ґ fmod ў®§ўа й Ґв §­ зҐ­ЁҐ x Ї® ¬®¤г«о y, Ї®«гз Ґ¬®Ґ
§­ зҐ­ЁҐ Є Є ®ЇЁб ­® ўлиҐ

*---------------------------------------------------------------------------*/
#pragma warn -rvl
double _FARFUNC fmod (double x, double y)
{
asm FLD DOUBLE (y)

asm mov ax, y [6]
asm shl ax, 1 /* €Ј­®аЁагҐвбп §­ Є®ўл© ЎЁв */
asm jz mod_resultZero /* …б«Ё ¤Ґ«ЁвҐ«м а ўҐ­ 0 */
asm cmp ax, 0FFE0h
asm jnb mod_isX /* …б«Ё ¤Ґ«ЁвҐ«м - ЎҐбЄ®­Ґз­®бвм */

asm FLD DOUBLE (x)

asm mov ax, x [6]
asm shl ax, 1
asm jz mod_xZero /* …б«Ё ¤Ґ«Ё¬®Ґ а ў­® 0 */
asm cmp ax, 0FFE0h
asm jnb mod_overflow /* …б«Ё ¤Ґ«Ё¬®Ґ - ЎҐбЄ®­Ґз­®бвм */

mod_keepTrying:
asm FPREM
asm push bx
asm mov bx, sp
asm FSTSW W0 (SS_ [bx]) /* C2 Ўг¤Ґв гбв ­®ў«Ґ­, Ґб«Ё ҐйҐ ­Ґ Є®­Ґж */
asm FWAIT
asm pop ax
asm sahf
asm jp mod_keepTrying /* C2 ЎЁв ®в®Ўа ¦ Ґвбп ­  д« Ј зҐв­®бвЁ */

asm FSTP st(1) /* бЎа®бЁвм ¤Ґ«ЁвҐ«м */

mod_end:
return;

/*
…б«Ё ¤Ґ«ЁвҐ«м - ЎҐбЄ®­Ґз­®бвм, в® ў®§ўа й Ґ¬ ¤Ґ«Ё¬®Ґ.
*/
mod_isX:
asm FSTP st(0) /* pop y off the stack */
asm FLD DOUBLE (x)
asm jmp short mod_end

/*
‚ᥠ¤агЈЁҐ д®а¬л ЎҐбЄ®­Ґз­®бвЁ ®в®Ўа ¦ овбп ў 0.
*/
mod_xZero:
mod_overflow:
asm FSTP st(0) /* pop x off the stack */
mod_resultZero:
asm FSTP st(0) /* pop y off the stack */
asm FLDZ
asm jmp short mod_end
}
#pragma warn .rvl



Соседние файлы в папке TASKS