Missing Odd-function

Ideas for improvement
Post Reply
User avatar
Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Missing Odd-function

Post by Dutchman » Tue Oct 22, 2019 10:03 am

Could an "ODD" and/or "EVEN" function be added :?:

Code: Select all

FOR i=-1 TO 2 STEP 0.5
  PRINT i;"is ";
  IF Odd(i) THEN PRINT "odd" ELSE PRINT "even or non-integer"
NEXT i
END
'
DEF Odd(n)
'returns 0 if n is non-integer or n is even
'else returnvalue is 1
  IF (ABS(n)-INT(ABS(n)))>0 THEN RETURN 0
  IF INT(n/2)=n/2 THEN RETURN 0 ELSE RETURN 1
END DEF
Result:
-1 is odd
-0.5 is even or non-integer
0 is even or non-integer
0.5 is even or non-integer
1 is odd
1.5 is even or non-integer
2 is even or non-integer
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 142
Joined: Tue Aug 06, 2019 3:03 pm

Re: Missing Odd-function

Post by kibernetik » Tue Oct 22, 2019 11:08 am

There is an example "Console/even or odd.txt".
Is it sufficient or dedicated function is necessary?

User avatar
Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Re: Missing Odd-function

Post by Dutchman » Tue Oct 22, 2019 2:51 pm

I use my function now, but I think it should be a basic function.
Preferably such that 'ODD(n) OR EVEN(n)' returns 0 if 'n' is non-integer.
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 142
Joined: Tue Aug 06, 2019 3:03 pm

Re: Missing Odd-function

Post by kibernetik » Tue Oct 22, 2019 3:46 pm

Thank you for the suggestion!

Post Reply