IsOdd() and IsEven()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: IsOdd() and IsEven()

Post by Little John »

MachineCode wrote:
Little John wrote:these two functions we can very easily write ourselves
Oh please, that's no argument.
Yes, I wrote that in the beginning of this thread. In the meantime, I've written a little more, but there's no need to repeat it here.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: IsOdd() and IsEven()

Post by MachineCode »

Yep, I've said my piece anyway. I won't continue the thread after this post.

BTW, you need a command that evaluates 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]. ;)
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: IsOdd() and IsEven()

Post by STARGÅTE »

MachineCode wrote:

Code: Select all

Debug Sqr(9) ; Why should Sqr() exist when Pow() can do the job?Debug Pow(9,0.5)
Sqr() is there for our convenience and readability
No ^^, Sqr() uses the special ASM-Code: FSQRT which is 10 times faster than the function Pow() :wink:
So it makes your code faster.

IsOdd() and IsEven() are parts of this list:
IsPositive(), IsNegative(), IsNull(), IsPrime(), IsFibonacci(), IsPowerOfTwo(), ...
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: IsOdd() and IsEven()

Post by MachineCode »

STARGÅTE wrote:No ^^, Sqr() uses the special ASM-Code: FSQRT which is 10 times faster than the function Pow() :wink:
So it makes your code faster.
And likewise, Fred's ASM versions of IsOdd() IsEven() would be way faster than any macro we could write. ;)
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

Re: IsOdd() and IsEven()

Post by naw »

Surely, you only need either IsOdd() - or - IsEven() since IsOdd(11)=true whereas IsOdd(10)=false
- if its neded at all of course
Ta - N
American Ninja
User
User
Posts: 24
Joined: Mon Jan 14, 2013 8:01 am

Re: IsOdd() and IsEven()

Post by American Ninja »

STARGÅTE wrote:IsPositive(), IsNegative()
The Sign() command does these. :mrgreen:
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: IsOdd() and IsEven()

Post by IdeasVacuum »

Tenaja wrote:Since most of them are done in Macros, maybe somebody can start a "standard" PB Macro library for "all of us" to use.
....now that's a good idea.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: IsOdd() and IsEven()

Post by davido »

Tenaja: Great idea!
DE AA EB
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: IsOdd() and IsEven()

Post by Little John »

MachineCode wrote:BTW, you need a command that evaluates 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]. ;)
:D Image
Post Reply