From: Roy Goldhammer on
I ran this:

declare @f float

set @f = 30

select sin(@f)

and got -0.988031624092862

What is this?


From: Dan on

"Roy Goldhammer" <royg(a)yahoo.com> wrote in message
news:eRKvnY0#KHA.5476(a)TK2MSFTNGP06.phx.gbl...
> I ran this:
>
> declare @f float
>
> set @f = 30
>
> select sin(@f)
>
> and got -0.988031624092862
>
> What is this?
>
>

The values for SIN, COS, and TAN are in radians, not degrees. You are seeing
the value of SIN(30 radians), which is correct.

--
Dan

From: Dan on

"Dan" <news(a)worldofspack.com> wrote in message
news:uw5$kq0#KHA.3176(a)TK2MSFTNGP05.phx.gbl...
>
> "Roy Goldhammer" <royg(a)yahoo.com> wrote in message
> news:eRKvnY0#KHA.5476(a)TK2MSFTNGP06.phx.gbl...
>> I ran this:
>>
>> declare @f float
>>
>> set @f = 30
>>
>> select sin(@f)
>>
>> and got -0.988031624092862
>>
>> What is this?
>>
>>
>
> The values for SIN, COS, and TAN are in radians, not degrees. You are
> seeing the value of SIN(30 radians), which is correct.
>

Forgot to mention that this should give you what you're expecting:


declare @f float

--converts degrees to radians
set @f = radians(@f)

select sin(@f)


which is 0.499999 (recurrring), and that is the float version of 0.5. Cast
the result to a decimal and it'll round out to 0.5

--
Dan

From: Dan on

"Dan" <news(a)worldofspack.com> wrote in message
news:uQrhzt0#KHA.3972(a)TK2MSFTNGP02.phx.gbl...
>
> "Dan" <news(a)worldofspack.com> wrote in message
> news:uw5$kq0#KHA.3176(a)TK2MSFTNGP05.phx.gbl...
>>
>> "Roy Goldhammer" <royg(a)yahoo.com> wrote in message
>> news:eRKvnY0#KHA.5476(a)TK2MSFTNGP06.phx.gbl...
>>> I ran this:
>>>
>>> declare @f float
>>>
>>> set @f = 30
>>>
>>> select sin(@f)
>>>
>>> and got -0.988031624092862
>>>
>>> What is this?
>>>
>>>
>>
>> The values for SIN, COS, and TAN are in radians, not degrees. You are
>> seeing the value of SIN(30 radians), which is correct.
>>
>
> Forgot to mention that this should give you what you're expecting:
>
>
> declare @f float
>
> --converts degrees to radians
> set @f = radians(@f)
>
> select sin(@f)
>
>
> which is 0.499999 (recurrring), and that is the float version of 0.5. Cast
> the result to a decimal and it'll round out to 0.5
>

Gah, having one of those days today. Here's the working code:

declare @f float

set @f = 30

--converts degrees to radians
set @f = radians(@f)

select sin(@f)


--
Dan

From: Erland Sommarskog on
Roy Goldhammer (royg(a)yahoo.com) writes:
> I ran this:
>
> declare @f float
>
> set @f = 30
>
> select sin(@f)
>
> and got -0.988031624092862
>
> What is this?

The sinus value of 30 radians. If you intended 30 degrees try:

select sin(radians(30E0))

(Using only "30" does not work, as the return type of radians() is the
same as the input type - quite silly if you ask me.)

At least you are not alone. The topic for SIN in Books Online says:

Returns the trigonometric sine of the specified angle, in radians

So far, so good, but then there is the example:

DECLARE @angle float
SET @angle = 45.175643
SELECT 'The SIN of the angle is: ' + CONVERT(varchar,SIN(@angle))
GO



--
Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx