Sin() and Cos() to optionally support degrees...

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Sin() and Cos() to optionally support degrees...

Post by Kale »

Please, is it possible for the Sin() and Cos() commands to support degrees and radians by using a built-in constant?

Code: Select all

Sin(Angle.f, #PB_Radians)
Sin(Angle.f, #PB_Degrees)

Cos(Angle.f, #PB_Radians)
Cos(Angle.f, #PB_Degrees)
I know some people prefer either one or the other, but it would be nice to support both. :)
--Kale

Image
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

I agree.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Also agree. (And props to me from me for restraint on the pun)
@}--`--,-- A rose by any other name ..
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

sinq cosq ?

(don't kill me, gfa malformed me!)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Then i'ld prefer two different functions, for speed/size reasons.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Radians is the standard in programming languages I think, but it would be convenient with a set of functions for either, or at least predefined conversion functions/(macros).
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

Degrees are mostly used in calculators and when I look virtual calculator software on the internet, it always has an option to switch between degrees and radian.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

I vote for differents functions. I prefer radians by default.
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

Would it not be better to keep Sin/Cos etc in degrees mode then have a Deg2Rad() command and vice verca?
~I see one problem with your reasoning: the fact is thats not a chicken~
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

As we have discuted before, sin and cos are often used for a lot of calculations. Any slow down of these functions will have a big speed impact on our programs!

I prefer differents dedicated functions for this reason :

"Sin" and "cos" in radians
"Sinq" and "cosq" or anything else, like "sind" and "cosd" for degrees.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

djes wrote:I prefer differents dedicated functions for this reason :

"Sin" and "cos" in radians
"Sinq" and "cosq" or anything else, like "sind" and "cosd" for degrees.
You misunderstand, my request was for an optional unit parameter to allow sin and cos to work with degrees. There is no need for seperate commands because when compiled the two different versions can be use behind the scenes. Just like the Plot(x, y) and plot(x, y, colour) commands where the first is not accelerated but the second is.
--Kale

Image
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Kale wrote:
djes wrote:I prefer differents dedicated functions for this reason :

"Sin" and "cos" in radians
"Sinq" and "cosq" or anything else, like "sind" and "cosd" for degrees.
You misunderstand, my request was for an optional unit parameter to allow sin and cos to work with degrees. There is no need for seperate commands because when compiled the two different versions can be use behind the scenes. Just like the Plot(x, y) and plot(x, y, colour) commands where the first is not accelerated but the second is.
I've used...
Procedure.f Radiant(x.f)
ProcedureReturn x*#PI/180
EndProcedure
...but maybe there could be a alternative (for speeder and not so precise calculation) which uses degrees...
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

in gfa sinq and cosq were doing lookups in a table instead of a real calculation to speed things up, and intermediate positions were just interpolated, not using the fpu

as degrees are mostly done in game purposes, this did make some sense

the question is just: would it make sense to do it this way on modern hardware, with modern fpu's ?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

blueznl wrote:in gfa sinq and cosq were doing lookups in a table instead of a real calculation to speed things up, and intermediate positions were just interpolated, not using the fpu?
Thats a good idea! :) As the only reason for asking this would be for games and the like, to quickly throw things around the screen.
--Kale

Image
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

Killswitch wrote:Would it not be better to keep Sin/Cos etc in degrees mode then have a Deg2Rad() command and vice verca?
Seems to be that PHP is really powerful:
http://php.net/rad2deg
Post Reply