A new one..

Started by xlar54, October 28, 2008, 03:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

xlar54

Ok, in BASIC try this:

PRINT 3 = 3

The answer is, of course, true, or '-1'

Why is the following false (0)

PRINT 3 = SQR(9)

The real answer requires more than just one sentence ;)

airship

#1
If you run the following program, it comes out TRUE for 1,2,4,7,8, and 9, and FALSE for 3,5,6, and 10. Is there anything telling in these numbers? If so, I haven't spotted it yet.

10 FOR X=1 TO 10
20 PRINT X,X*X,SQR(X*X),X=SQR(X*X)
30 NEXT


If you substitute X=INT(SQR(X*X)) at the end of line 20, they all test true. So it's in the floating point routine somewhere. But if so, why doesn't it display when you print SQR(X*X)?

If it means anything, I have always used INT when I make integer comparisons after any floating point calculation. And ALL calculations in Commodore BASICs are in floating point. Did you know that even if you use integer variables, BASIC calculates in floating point and then converts the result to integer? Sad but true.

Anyway, does xlar's problem happen under other Microsoft BASICs? Anyone?

I'll give it some more thought.

Postscript: Wikipedia says this about Commodore's BASIC interpreter:

QuoteThe native number format of Commodore BASIC, like that of its parent MS BASIC, was floating point. Most of the contemporary BASIC implementations used one byte for the characteristic (exponent) and three bytes for the mantissa. This led to problems in business applications since the accuracy of a floating point number using a three-byte mantissa is only about 6.5 decimal digits, and round-off error is common. Commodore, however, used MS BASIC's four-byte mantissa, which made their BASIC much more adapted for business than most other BASICs of the era.
Here's a great resource that discusses in depth the various flavors of Microsoft BASIC for different machines: http://www.pagetable.com/?p=46
Serving up content-free posts on the Interwebs since 1983.
History of INFO Magazine

airship

#2
So... did I kill this one, or is there more to know? ???

Interesting tidbit I ran into while doing research:
Quotea BASIC compiler is available for the 8032 and the 4032. The Commodore Integer BASIC Compiler runs about 100 times faster than BASIC, but it only handles integer math. It generates true machine code and is best for compiling subroutines. Another compiler is PETSpeed, which generates pseudocode and increases execution speed by a factor of approximately 3 to 20 times, depending on the task. It handles floating point math, and is easier to use to compile previously written programs since it handles PET/CBM BASIC syntax.

Floating point BASIC compilers for the C64 and C128 we've all seen before. But was there an uber-fast integer BASIC compiler for them like the Commodore brand version for the PET?
Serving up content-free posts on the Interwebs since 1983.
History of INFO Magazine

Blacklord

Here's the screen shot for GW Basic - this is under XP on a 64 bit Athlon, I also ran it on the XT just to be certain & it gave the same results as the modern machine - looks like it's a Commie issue, dunno about other vintage machines but can try it on a few of the other I have here that run a version of M$ Basic.


airship

I'm answering my own question about C64/128 integer BASIC compilers.

This is from the Commodore Languages List. Only two compilers for the C64 specifically mention 'integer', though it could be an option for others. Unfortunately, there are no integer compilers listed that support the C128.

The links below are broken. Craig Bruce still has the Diablo compiler, but it's in this directory: http://www.csbruce.com/~csbruce/cbm/ftp/misc/ You can also downlaod the Diablo compiler as a d64 file from: http://www.cronos.toucansurf.com/development_tools.htm
QuoteDiabolo V3.2 [C64] (1994, Wilfried Elmenreich)
Integer BASIC compiler. Library concept with static/dynamic linkers. Limited to 16 bit integers only, which can be quite inefficient. Has trouble with calling outside ML routines and has a limited command subset support. That said, it generates blindingly fast code compared to other compilers (beat Abacus BASIC 64's o-code object by a wide margin) and is very configurable about where to put variables and o-code at. Documentation is in German.
On-line program information is available.
ftp://csbruce.dhs.org/pub/cbm/misc/diabolo3.zip
I can't find an information or download site for the Laser Basic compiler below, though it seems it was also available for the Amstrad and Sinclair.
QuoteLaser Basic Compiler [C64] (David Hunter, Oasis Software)
Compiles BASIC V2.0 programs with Laser Basic Extension extensions. Has option to compile integer only programs for faster performance. Does not need Laser Basic to compile Laser Basic Extensions and to run them. Free run-time license.

Serving up content-free posts on the Interwebs since 1983.
History of INFO Magazine

wte

Quote from: airship on November 18, 2008, 05:48 AM
This is from the Commodore Languages List. Only two compilers for the C64 specifically mention 'integer', though it could be an option for others. Unfortunately, there are no integer compilers listed that support the C128.
BASIC 128 (Data Becker or Abacus in US) has the option to handle all variables as integer. This improves the speed a lot. Also you can define (with special compiler codes) "normal" FP variables as intergers. That speeds up loops like FOR I = 1 TO 10...

Regards WTE