[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result
Pete's QBASIC Site Discuss QBasic, Freebasic, QB64 and more 2008-12-25T18:01:36-05:00 http://petesqbsite.com/phpBB3/app.php/feed/topic/2833 2008-12-25T18:01:36-05:00 2008-12-25T18:01:36-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18573#p18573 <![CDATA[divisible by 2]]> He compiles Everything...........

Now to your decimal number code: You can just split the string number at the INSTR(number$, ".") and use both sides of it as strings. Then just use VAL and MOD 2 also. But what is the point of finding even decimal point values anyhow? The point accuracy in QB is ALWAYS questionable while Integers don't have any problems!

Ted

Statistics: Posted by burger2227 — Thu Dec 25, 2008 6:01 pm


]]>
2008-12-25T17:39:13-05:00 2008-12-25T17:39:13-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18572#p18572 <![CDATA[divisible by 2]]> Statistics: Posted by Ralph — Thu Dec 25, 2008 5:39 pm


]]>
2008-12-25T17:01:22-05:00 2008-12-25T17:01:22-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18569#p18569 <![CDATA[divisible by 2]]>
I have learned that arguing with Moneo is a waste of time anyhow! How he can figure out what a number is, is beyond me. He does not use the QB IDE at all.

Statistics: Posted by burger2227 — Thu Dec 25, 2008 5:01 pm


]]>
2008-12-25T11:38:09-05:00 2008-12-25T11:38:09-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18568#p18568 <![CDATA[divisible by 2]]> The reason I used AND in my code was to show that the result obtained by using AND, as well as a number we know has a small remainder in QuickBASIC (in ALL qBASICs?). For the case of testing integers, AND works fine, giving the correct mathematical result. However, it does not give the correct QuickBASIC result, which has a remainder.
My use of 5^2 is on purpose, because it has a remainder in qb. So, I use it to show that we have to be careful how we use derived values, which may not be exact in qb.

Ted:
I would really like to see a program that does not use integers and can tell me if the Single or Double value is divisible by 2.
Dos this program not satisfy your question?:

Code:

again:CLSPRINT " To determing if a number is divisible by 2, enter number:"LOCATE , 2LINE INPUT num$num = VAL(num$)IF INT(num) <> num THEN  decimals = LEN(num$) - INSTR(num$, ".")  numINT = VAL(num$) * 10 ^ decimalsELSE  numINT = numEND IFLOCATE CSRLIN - 1IF numINT AND 1 THEN  PRINT " "; num$; " is NOT divisible by 2 "ELSE  PRINT " "; num$; " is divisible by 2"END IF

Statistics: Posted by Ralph — Thu Dec 25, 2008 11:38 am


]]>
2008-12-25T02:16:36-05:00 2008-12-25T02:16:36-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18565#p18565 <![CDATA[divisible by 2]]> Statistics: Posted by burger2227 — Thu Dec 25, 2008 2:16 am


]]>
2008-12-24T20:02:59-05:00 2008-12-24T20:02:59-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18564#p18564 <![CDATA[divisible by 2]]>
Hello,, Moneo!

Here is another quirk I find in QuickBASIC 4.5.
I ran the code in G-W BASIC, and got Odd. 0, ODD, odd, 0, A is odd.
I ran the code in QuickBASIC and got Odd, -1.734723E-18, EVEN, even, -1.734723E-18, A is odd.

So, the value that qb returns for 5 ^ 2 is not truly the integer 25, since the above shows that the difference is not 0.

It seems to me that your use of AND to detect odd or even would not be proper in qb, since further use of 5 ^ 2 as an integer would not be true in qb.

To truly get the exact integer 25, I find that Ted's answer of assigning a variable to it, seems to be the only way to go.


[code[CLS
IF F ^ 2 AND 1 THEN PRINT "Odd" ELSE PRINT "Even"
PRINT 5 ^ 2 - 25
IF 5 ^ 2 - 25 = 0 THEN PRINT "ODD" ELSE PRINT "EVEN"
IF INT(5 ^ 2) - 25 = 0 THE PRINT "odd" ELSE PRINT "even"
A = 5 ^ 2
IF A = 25 = 0 THEN PRINT "A is odd" ELSE PRINT "A is even"
Hi Ralph,

In my solution above for testing for odd or even numbers, I specifically said "assuming that the number is an integer." Your code, without any DEFtype statement, will be working with the default type of Single.

Also, we already know that expressions with exponentiation are computed using floating point, and the result may give you an answer in floating point notation. This is especially true when you print the expression out without storing it first into a variable.

I don't understand why you often chose to use expressions with exponentiation, like 5 ^ 2 - 25, for testing code that has nothing to do with exponentiation.

My odd/even solution is based on using the AND operator, and yet of the 4 statements of yours that determine odd/even, only the first one uses the AND operator. What was your thinking here?

Regards..... Moneo

Statistics: Posted by moneo — Wed Dec 24, 2008 8:02 pm


]]>
2008-12-24T20:01:33-05:00 2008-12-24T20:01:33-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18563#p18563 <![CDATA[divisible by 2]]>
Hello,, Moneo!

Here is another quirk I find in QuickBASIC 4.5.
I ran the code in G-W BASIC, and got Odd. 0, ODD, odd, 0, A is odd.
I ran the code in QuickBASIC and got Odd, -1.734723E-18, EVEN, even, -1.734723E-18, A is odd.

So, the value that qb returns for 5 ^ 2 is not truly the integer 25, since the above shows that the difference is not 0.

It seems to me that your use of AND to detect odd or even would not be proper in qb, since further use of 5 ^ 2 as an integer would not be true in qb.

To truly get the exact integer 25, I find that Ted's answer of assigning a variable to it, seems to be the only way to go.


[code[CLS
IF F ^ 2 AND 1 THEN PRINT "Odd" ELSE PRINT "Even"
PRINT 5 ^ 2 - 25
IF 5 ^ 2 - 25 = 0 THEN PRINT "ODD" ELSE PRINT "EVEN"
IF INT(5 ^ 2) - 25 = 0 THE PRINT "odd" ELSE PRINT "even"
A = 5 ^ 2
IF A = 25 = 0 THEN PRINT "A is odd" ELSE PRINT "A is even"
Hi Ralph,

In my solution above for testing for odd or even numbers, I specifically said "assuming that the number is an integer." Your code, without any DEFtype statement, will be working with the default type of Single.

Also, we already know that expressions with exponentiation are computed using floating point, and the result may give you an answer in floating point notation. This is especially true when you print the expression out without storing it first into a variable.

I don't understand why you often chose to use expressions with exponentiation, like 5 ^ 2 - 25, for testing code that has nothing to do with exponentiation.

My odd/even solution is based on using the AND operator, and yet of the 4 statements of yours that determine odd/even, only the first one uses the AND operator. What was your thinking here?

Regards..... Moneo

Statistics: Posted by moneo — Wed Dec 24, 2008 8:01 pm


]]>
2008-12-24T18:18:32-05:00 2008-12-24T18:18:32-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18562#p18562 <![CDATA[divisible by 2]]>
Here is another quirk I find in QuickBASIC 4.5.
I ran the code in G-W BASIC, and got Odd. 0, ODD, odd, 0, A is odd.
I ran the code in QuickBASIC and got Odd, -1.734723E-18, EVEN, even, -1.734723E-18, A is odd.

So, the value that qb returns for 5 ^ 2 is not truly the integer 25, since the above shows that the difference is not 0.

It seems to me that your use of AND to detect odd or even would not be proper in qb, since further use of 5 ^ 2 as an integer would not be true in qb.

To truly get the exact integer 25, I find that Ted's answer of assigning a variable to it, seems to be the only way to go.


[code[CLS
IF F ^ 2 AND 1 THEN PRINT "Odd" ELSE PRINT "Even"
PRINT 5 ^ 2 - 25
IF 5 ^ 2 - 25 = 0 THEN PRINT "ODD" ELSE PRINT "EVEN"
IF INT(5 ^ 2) - 25 = 0 THE PRINT "odd" ELSE PRINT "even"
A = 5 ^ 2
IF A = 25 = 0 THEN PRINT "A is odd" ELSE PRINT "A is even"

Statistics: Posted by Ralph — Wed Dec 24, 2008 6:18 pm


]]>
2008-12-19T22:19:58-05:00 2008-12-19T22:19:58-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18553#p18553 <![CDATA[divisible by 2]]>
This is really a dumb question but how can you check if a number is a multiple of 2? I've tried everything I could think of.

ie.
IF string% = 'divisible by 2' THEN

Thanks
Qbasicfreak
Saying that a number is a multiple of 2 is the same as saying that the number is even.

Assuming that the number is a integer, here's a simple way of determining whether it is odd or even.

defint a-z
IF Number AND 1 THEN
PRINT "Number is odd"
ELSE
PRINT "Number is even"
END IF

However, this method will consider the Number zero as even.

How it works. If the low order bit of a number is a one, then the number is odd, otherwise it's even.
So, when you AND with a 1, if the low order bit of the Number is also a one, then the ressult of "Number AND 1" gives you a TRUE condition which means that the Number is odd. Otherwise, the low order bit is zero, which means that the Number is even.

Regards..... Moneo

Statistics: Posted by moneo — Fri Dec 19, 2008 10:19 pm


]]>
2008-12-19T22:14:11-05:00 2008-12-19T22:14:11-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18552#p18552 <![CDATA[divisible by 2]]> Statistics: Posted by Ralph — Fri Dec 19, 2008 10:14 pm


]]>
2008-12-19T13:23:47-05:00 2008-12-19T13:23:47-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18551#p18551 <![CDATA[divisible by 2]]>

Code:

CLSPRINTREM Using single precision with decimals, some of the mess is removed.DIM k AS SINGLEFOR k = 1 TO 4 STEP .125PRINT k,NEXTPRINTFOR k = 2 TO 4 STEP .125PRINT k,NEXTPRINTPRINTFOR k = 2.25 TO 4 STEP .125PRINT k,NEXTPRINT
A tenth creates a Single accuracy error.

Ted

Statistics: Posted by burger2227 — Fri Dec 19, 2008 1:23 pm


]]>
2008-12-19T16:51:05-05:00 2008-12-19T04:22:57-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18550#p18550 <![CDATA[divisible by 2]]> Statistics: Posted by roy — Fri Dec 19, 2008 4:22 am


]]>
2008-12-18T17:39:58-05:00 2008-12-18T17:39:58-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18549#p18549 <![CDATA[divisible by 2]]>

Code:

CLSPRINTREM Using single precision with decimals, some of the mess is removed.DIM k AS SINGLEFOR k = 1 TO 4 STEP .1PRINT k,NEXTPRINTFOR k = 2 TO 4 STEP .1PRINT k,NEXTPRINTPRINTFOR k = 2.3 TO 4 STEP .1PRINT k,NEXTPRINT

Statistics: Posted by Ralph — Thu Dec 18, 2008 5:39 pm


]]>
2008-12-17T12:52:38-05:00 2008-12-17T12:52:38-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18547#p18547 <![CDATA[divisible by 2]]>
Double precision (DOUBLE in QBASIC) 8 bytes = 64 bits:
Sign: 1 bit
Exponent: 11 bits
Mantissa: 52 bits

Single precision (SINGLE in QBASIC) 4 bytes = 32 bits:
Sign: 1 bit
Exponent: 8 bits
Mantissa: 23 bits

The mantissa holds all of the decimal point values. The Exponent of Single is 8 bits or ONE byte. Thus it does not have the same Double error problem.

Ted

Statistics: Posted by burger2227 — Wed Dec 17, 2008 12:52 pm


]]>
2008-12-19T18:12:50-05:00 2008-12-17T05:08:30-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=18546#p18546 <![CDATA[divisible by 2]]>
CLS
DIM i AS DOUBLE
REM Using double precision with decimals, very messy.
FOR i = 1 TO 4 STEP .1
PRINT i,
NEXT
PRINT
REM Using single precision with decimals, some of the mess is removed.
FOR k = 1 TO 4 STEP .1
PRINT k,
NEXT
PRINT
REM Using a decimal that fits with the computers bit pattern, no problems.
FOR i = 1 TO 4 STEP .125
PRINT i,
NEXT
SYSTEM

Statistics: Posted by roy — Wed Dec 17, 2008 5:08 am


]]>