# Board index » delphi » function Sin(X: Real): Real;

## function Sin(X: Real): Real;

Can anyone tell me how the "function Sin(X: Real): Real;" is build ???

## Re:function Sin(X: Real): Real;

##### Quote
AGH wrote:

> Can anyone tell me how the "function Sin(X: Real): Real;" is build ???

There are several solutions, I think Borland used a Taylor
series, but you should ask this question in the
news:borland.public.turbopascal
group. But: attach directly via forums.inprise.com, not with your
local provider.
There are some really good experts who seem to be former Borland
employees.

I have the ASM source in my RTL pack, but it is not free and thus
may not be distributed, sorry. Assuming that you mean the 6-byte
real procedures.

Regards,
--
Franz Glaser, Glasau 3, A-4191 Vorderweissenbach Austria +43-7219-7035-0
Muehlviertler Elektronik Glaser.  Industrial control and instrumentation
http://members.eunet.at/meg-glaser/    http://members.xoom.com/f_glaser/
http://www.geocities.com/~franzglaser/            http://start.at/bedarf

## Re:function Sin(X: Real): Real;

On Mon, 25 Oct 1999 13:40:23 GMT, "AGH"

##### Quote
<arnt.gustav.haagen...@nt.telia.no> wrote:
> Can anyone tell me how the "function Sin(X: Real): Real;" is build ???

For type Real and {\$N-} it is evaluated as

x^3   x^5   x^7    x^9   x^11   x^13   x^15
x - --- + --- - ---  + --- - ---- + ---- - ----
3!    5!     7!     9!    11!    13!    15!

i.e. as the straighforward Taylor expansion after reducing the
argument to some value in the interval [0..pi/2]. The coefficiensts
are stored in reverse order

a[0] = -1/15! etc..

and the expression is evaluated as :

z   = x^2
sin =
(((((((a[0]*z+a[1])*z+a[2])*z+a[3])*z+a[4])*z+a[5])*z+a[6])*z+1)*x

For copro (single,double,extended) types and REAL {\$N+}, the copro
instruction FSIN is called which does something similar.

Regards
Horst

## Re:function Sin(X: Real): Real;

##### Quote
horst.krae...@t-online.de (Horst Kraemer) wrote:
>For type Real and {\$N-} it is evaluated as

>            x^3   x^5   x^7    x^9   x^11   x^13   x^15
>    x - --- + --- - ---  + --- - ---- + ---- - ----
>            3!    5!     7!     9!    11!    13!    15!

>i.e. as the straighforward Taylor expansion after reducing the
>argument to some value in the interval [0..pi/2]. The coefficiensts
>are stored in reverse order

>a[0] = -1/15! etc..

>and the expression is evaluated as :

>z   = x^2
>sin =
>(((((((a[0]*z+a[1])*z+a[2])*z+a[3])*z+a[4])*z+a[5])*z+a[6])*z+1)*x

That's not the best way to do it.  There are better ways to do
it than a truncated Taylor series.  You can get the same
accuracy with fewer terms if you chose the coefficients better.

Jud McCranie

## Re:function Sin(X: Real): Real;

JRS:  In article <b5ZQ3.250\$Jnn.179823...@news.telia.no> of Mon, 25 Oct
1999 13:40:23 in news:comp.lang.pascal.borland, AGH <arnt.gustav.haagens

##### Quote
e...@nt.telia.no> wrote:
>Can anyone tell me how the "function Sin(X: Real): Real;" is build ???

Don't use type REAL; it is inefficient (except in special cases) ; see
<URL: http://www.merlyn.demon.co.uk/pas-real.htm>; use the IEEE types
single, double, or extended.

The implementation of Sin will depend on the state of the \$N/\$E options.

With the IEEE types, and compiling for a FPU, the implementation will be
based on a simple FPU instruction, with (I guess) pre-scaling.  As TP/BP
rarely recognise the existence of better than a 286, however, the FPU
instruction may not be what a reader of the full instruction set might
expect.

The implementation of the basic trigonometrical primitives in a FPU is a
design-time choice, and may vary; ISTR, very vaguely, that some use
Cordic and some do not.  Try back issues of "IEEE Micro" journal, if an

Remember, some FPUs were designed by the folks who implemented FDIV ...

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
Web <URL: http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper 4-line sig. separator is as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

## Re:function Sin(X: Real): Real;

"Ing. Franz Glaser" <meg-gla...@eunet.at> wrote:

##### Quote
> AGH wrote:

> > Can anyone tell me how the "function Sin(X: Real): Real;" is build
> > ???

> There are several solutions, I think Borland used a Taylor
> series, but you should ask this question in the
> news:borland.public.turbopascal
> group. But: attach directly via forums.inprise.com, not with your
> local provider.
> There are some really good experts who seem to be former Borland
> employees.

> I have the ASM source in my RTL pack, but it is not free and thus
> may not be distributed, sorry. Assuming that you mean the 6-byte
> real procedures.

For those readers new to this group, Borland made the RTL source of
TP6/7 available for a fee, and gave it as a bonus with BP7. Norbert
Juffa completely rewrote the TP6 RTL, and ported most of his changes to
the BP7 RTL. Programs compiled with either are usually smaller and
always faster than those using the Borland RTL. He also made "real"
arithmetic as IEEE compliant as possible.

Both are libraries are available on Garbo,

TP6: ftp://garbo.uwasa.fi/pc/turbopa6/tpl60n19.zip
BP7: ftp://garbo.uwasa.fi/pc/turbopa7/bpl70n16.zip

Inside the archive you will find a file called "ARISOURC.ZIP", which
contains the full source of Norbert's 6-byte REAL replacement code,
including the trigonometrics.

Robert
--
Robert AH Prins
prin...@willis.com

Sent via Deja.com http://www.deja.com/

## Re:function Sin(X: Real): Real;

You can compute the function sin(x) using a power series formula that you
can found on any good mathematic analisys book.
You can also use a lookup table : you can build a table whith a finite
number of samples of function sin(x) an than interpolate for gaining the
result.

Cleto Azzani

##### Quote
AGH <arnt.gustav.haagen...@nt.telia.no> wrote in message

b5ZQ3.250\$Jnn.179823...@news.telia.no...
##### Quote
> Can anyone tell me how the "function Sin(X: Real): Real;" is build ???