comp.lang.ada
 help / color / mirror / Atom feed
* Many overlook the possibility sin(x,360.0) ?
@ 2017-05-01  5:22 reinert
  2017-05-01  8:50 ` hreba
  2017-05-01 17:46 ` Nasser M. Abbasi
  0 siblings, 2 replies; 10+ messages in thread
From: reinert @ 2017-05-01  5:22 UTC (permalink / raw)


Hi,

Not a big philosophical question, but:

I have often seen in (others) Ada code that many prefer to use for example sin(x) where they first calculate x := rad_per_degree*degrees.

Why they do not use sin(degrees,360.0) if they need to use degree. Are there a good reason? Using sin(x, 3600.0) seems to keep the code simpler. Sometimes I even use sin(x,period).

reinert


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Many overlook the possibility sin(x,360.0) ?
  2017-05-01  5:22 Many overlook the possibility sin(x,360.0) ? reinert
@ 2017-05-01  8:50 ` hreba
  2017-05-01 17:46 ` Nasser M. Abbasi
  1 sibling, 0 replies; 10+ messages in thread
From: hreba @ 2017-05-01  8:50 UTC (permalink / raw)


On 05/01/2017 07:22 AM, reinert wrote:
> Hi,
>
> Not a big philosophical question, but:
>
> I have often seen in (others) Ada code that many prefer to use for example sin(x) where they first calculate x := rad_per_degree*degrees.
>
> Why they do not use sin(degrees,360.0) if they need to use degree. Are there a good reason? Using sin(x, 3600.0) seems to keep the code simpler. Sometimes I even use sin(x,period).
>
> reinert
>

For calculations inside a program, using the same unit all over is 
simpler, because you don't have to do any conversion again and again. 
Isn't a function with one parameter simpler than one with two, which 
would execute such a conversion at each call? So one would use meters 
(just an example) for all lengths inside a program, and convert them to 
other units (e.g. micrometers) only at the interface with humans, when 
necessary.

If one unit has an advantage over all others, such as radians have for 
the numerical calculation of trigonometric functions, you use that one, 
internally.
-- 
Frank Hrebabetzky		+49 / 6355 / 989 5070


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Many overlook the possibility sin(x,360.0) ?
  2017-05-01  5:22 Many overlook the possibility sin(x,360.0) ? reinert
  2017-05-01  8:50 ` hreba
@ 2017-05-01 17:46 ` Nasser M. Abbasi
  2017-05-01 20:04   ` Dmitry A. Kazakov
  1 sibling, 1 reply; 10+ messages in thread
From: Nasser M. Abbasi @ 2017-05-01 17:46 UTC (permalink / raw)


On 5/1/2017 12:22 AM, reinert wrote:
> Hi,
>
> Not a big philosophical question, but:
>
> I have often seen in (others) Ada code that many prefer to use for example sin(x)
>where they first calculate x := rad_per_degree*degrees.
>
> Why they do not use sin(degrees,360.0) if they need to use degree.
>Are there a good reason? Using sin(x, 3600.0) seems to keep the code
>simpler. Sometimes I even use sin(x,period).
>
> reinert
>

btw,  These are implemented in other languages as follows:

In Mathematica one can type

Sin[ 360 Degree]

in Matlab one uses sind(360) instead of sin() for degrees.

--Nasser



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Many overlook the possibility sin(x,360.0) ?
  2017-05-01 17:46 ` Nasser M. Abbasi
@ 2017-05-01 20:04   ` Dmitry A. Kazakov
  2017-05-01 20:46     ` Shark8
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry A. Kazakov @ 2017-05-01 20:04 UTC (permalink / raw)


On 2017-05-01 19:46, Nasser M. Abbasi wrote:
> On 5/1/2017 12:22 AM, reinert wrote:

>> Not a big philosophical question, but:
>>
>> I have often seen in (others) Ada code that many prefer to use for
>> example sin(x)
>> where they first calculate x := rad_per_degree*degrees.
>>
>> Why they do not use sin(degrees,360.0) if they need to use degree.
>> Are there a good reason? Using sin(x, 3600.0) seems to keep the code
>> simpler. Sometimes I even use sin(x,period).

I remember the first thing they taught us during the first semester was 
to ditch degrees...

> btw,  These are implemented in other languages as follows:
>
> In Mathematica one can type
>
> Sin[ 360 Degree]
>
> in Matlab one uses sind(360) instead of sin() for degrees.

Which is *exactly* same as in Ada.

The notation 300 Degree is <value><unit> = <value>*<unit>. 
rad_per_degree = Degree = Pi/180.0 is <unit> here (dimensionless).

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Many overlook the possibility sin(x,360.0) ?
  2017-05-01 20:04   ` Dmitry A. Kazakov
@ 2017-05-01 20:46     ` Shark8
  2017-05-02  6:37       ` reinert
  0 siblings, 1 reply; 10+ messages in thread
From: Shark8 @ 2017-05-01 20:46 UTC (permalink / raw)


On Monday, May 1, 2017 at 2:04:13 PM UTC-6, Dmitry A. Kazakov wrote:
> On 2017-05-01 19:46, Nasser M. Abbasi wrote:
> > On 5/1/2017 12:22 AM, reinert wrote:
> 
> >> Not a big philosophical question, but:
> >>
> >> I have often seen in (others) Ada code that many prefer to use for
> >> example sin(x)
> >> where they first calculate x := rad_per_degree*degrees.
> >>
> >> Why they do not use sin(degrees,360.0) if they need to use degree.
> >> Are there a good reason? Using sin(x, 3600.0) seems to keep the code
> >> simpler. Sometimes I even use sin(x,period).
> 
> I remember the first thing they taught us during the first semester was 
> to ditch degrees...

That is honestly stupid; given how I remember it being done "in the name of 'accuracy' -- the problem is that it's not more accurate: 90° *IS* π/2 radians.

Difficulty/complexity of handling is completely discrete from accuracy, and if we wanted a good constant for circles it would be 2π -- as shown here: http://www.math.utah.edu/%7Epalais/pi.pdf (see also: http://tauday.com/tau-manifesto )

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Many overlook the possibility sin(x,360.0) ?
  2017-05-01 20:46     ` Shark8
@ 2017-05-02  6:37       ` reinert
  2017-05-02  8:35         ` Dmitry A. Kazakov
  0 siblings, 1 reply; 10+ messages in thread
From: reinert @ 2017-05-02  6:37 UTC (permalink / raw)


My point is that "x" and "period" has the same dimmension in sin(x,period).

"x" (and "Period") may not represent radians or degree. "x" may represent for example time (seconds) or meters - or lightyears :-)  In some way "radians" and "degree" are "dimmensionless" varaiables (do not miss-understand me here).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Many overlook the possibility sin(x,360.0) ?
  2017-05-02  6:37       ` reinert
@ 2017-05-02  8:35         ` Dmitry A. Kazakov
  2017-05-03  4:12           ` reinert
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry A. Kazakov @ 2017-05-02  8:35 UTC (permalink / raw)


On 02/05/2017 08:37, reinert wrote:
> My point is that "x" and "period" has the same dimmension in sin(x,period).

Yes

> "x" (and "Period") may not represent radians or degree. "x" may
> represent for example time (seconds) or meters - or lightyears :-)

x/period must be dimensionless, which is satisfied when both have same 
dimension.

> In
> some way "radians" and "degree" are "dimmensionless" varaiables (do not
> miss-understand me here).

Yes, arguments of all non-algebraic functions must be dimensionless. So 
sine goes.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Many overlook the possibility sin(x,360.0) ?
  2017-05-02  8:35         ` Dmitry A. Kazakov
@ 2017-05-03  4:12           ` reinert
  2017-05-03  7:18             ` Dmitry A. Kazakov
  0 siblings, 1 reply; 10+ messages in thread
From: reinert @ 2017-05-03  4:12 UTC (permalink / raw)




To be a bit precise: "x" and "period" must be of the same unit (which *include* same dimension) in sin(x,period). 

Here is an attempt to make clean code plotting an approximation of a circle
(using two arguments for cos and sin):

   for i in 0 .. 35 loop
       vertex(radius * (cos (real (i), 36.0), sin (real (i), 36.0)));
   end loop;


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Many overlook the possibility sin(x,360.0) ?
  2017-05-03  4:12           ` reinert
@ 2017-05-03  7:18             ` Dmitry A. Kazakov
  2017-05-08 17:37               ` reinert
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry A. Kazakov @ 2017-05-03  7:18 UTC (permalink / raw)


On 03/05/2017 06:12, reinert wrote:

> Here is an attempt to make clean code plotting an approximation of a circle
> (using two arguments for cos and sin):
>
>    for i in 0 .. 35 loop
>        vertex(radius * (cos (real (i), 36.0), sin (real (i), 36.0)));
>    end loop;

I would rather:

declare
    Points   : constant := 36;
    To_Angle : constant Real := 2.0 * Pi / Real (Points);
begin
    for i in 0..Points - 1 loop
       declare
          Angle : constant Real := Real (I) * To_Angle;
       begin
          vertex (radius * (cos (Angle), sin (Angle)));
       end;
    end loop;
end;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Many overlook the possibility sin(x,360.0) ?
  2017-05-03  7:18             ` Dmitry A. Kazakov
@ 2017-05-08 17:37               ` reinert
  0 siblings, 0 replies; 10+ messages in thread
From: reinert @ 2017-05-08 17:37 UTC (permalink / raw)


On Wednesday, May 3, 2017 at 9:18:23 AM UTC+2, Dmitry A. Kazakov wrote:
> On 03/05/2017 06:12, reinert wrote:
> 

> 
> I would rather:
> 
> declare
>     Points   : constant := 36;
>     To_Angle : constant Real := 2.0 * Pi / Real (Points);
> begin
>     for i in 0..Points - 1 loop
>        declare
>           Angle : constant Real := Real (I) * To_Angle;
>        begin
>           vertex (radius * (cos (Angle), sin (Angle)));
>        end;
>     end loop;
> end;
> 

It depends on the perception of cos/sin (could also use complex exponent to make it even shorter).

reinert

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-05-08 17:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-01  5:22 Many overlook the possibility sin(x,360.0) ? reinert
2017-05-01  8:50 ` hreba
2017-05-01 17:46 ` Nasser M. Abbasi
2017-05-01 20:04   ` Dmitry A. Kazakov
2017-05-01 20:46     ` Shark8
2017-05-02  6:37       ` reinert
2017-05-02  8:35         ` Dmitry A. Kazakov
2017-05-03  4:12           ` reinert
2017-05-03  7:18             ` Dmitry A. Kazakov
2017-05-08 17:37               ` reinert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox