Are there integer numbers in the basic of x16 please?

All aspects of programming on the Commander X16.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Are there integer numbers in the basic of x16 please?

Post by funkheld »

Hi good afternoon.
Are there integer numbers in the basic of x16 please?

Thanks.
greeting
User avatar
ahenry3068
Posts: 1131
Joined: Tue Apr 04, 2023 9:57 pm

Re: Are there integer numbers in the basic of x16 please?

Post by ahenry3068 »

funkheld wrote: Mon Mar 25, 2024 1:19 pm Hi good afternoon.
Are there integer numbers in the basic of x16 please?

Thanks.
greeting
There are. X% is a Signed 16 bit integer. X is 5 byte floating point variable.

IN THIS BASIC THOUGH THERE IS NO INTEGER MATH. ALL MATH ROUTINES ARE FLOATING POINT.

Using an Integer can actually Slow things down !!!!!!!! The integer is converted internally to Floating Point for Math operations.


The one part it does make sense to use Integer is in Arrays. Integers in an Array take 2 bytes per element. Floats take 5 bytes per element.
Last edited by ahenry3068 on Mon Mar 25, 2024 2:18 pm, edited 1 time in total.
Slevin
Posts: 29
Joined: Wed Mar 06, 2024 8:04 pm

Re: Are there integer numbers in the basic of x16 please?

Post by Slevin »

ahenry3068 wrote: Mon Mar 25, 2024 2:00 pm Floats take 5 bytes per element.
Is this a proprietary floating point representation, or is the 5th byte reserved for some kind of meta data? At least according to the birth date of the IEEE 754 standard I assume that it must be proprietary in some kind, but 5 byte must have a requirement. Can someone eplain?
User avatar
ahenry3068
Posts: 1131
Joined: Tue Apr 04, 2023 9:57 pm

Re: Are there integer numbers in the basic of x16 please?

Post by ahenry3068 »

Slevin wrote: Mon Mar 25, 2024 2:11 pm
ahenry3068 wrote: Mon Mar 25, 2024 2:00 pm Floats take 5 bytes per element.
Is this a proprietary floating point representation, or is the 5th byte reserved for some kind of meta data? At least according to the birth date of the IEEE 754 standard I assume that it must be proprietary in some kind, but 5 byte must have a requirement. Can someone eplain?
Its modified by Commodore

Commodore uses a variant of IEEE-754 Floating point numbers. The short version is that BASIC stores the number using 5 bytes. 4 bytes hold the significant digits (31 binary digits, plus a sign) and 1 byte holds the exponent, aka the number of places to move the decimal point.Sep 30, 2018

Commodore BASIC Integer Size - Lemon64

Lemon64
https://www.lemon64.com
Slevin
Posts: 29
Joined: Wed Mar 06, 2024 8:04 pm

Re: Are there integer numbers in the basic of x16 please?

Post by Slevin »

Aha, another day I've learned something new, many thanks.

Slowly but surely I'm becoming omniscient. I can hardly wait...
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: Are there integer numbers in the basic of x16 please?

Post by funkheld »

Thanks for the info.

Vera etc. requires data with vpoke as 1 byte, hibyte and lobyte. That means you don't have to worry about that if you take poke/vpoke.
you just pass the number/value?

Thanks.
greeting
User avatar
ahenry3068
Posts: 1131
Joined: Tue Apr 04, 2023 9:57 pm

Re: Are there integer numbers in the basic of x16 please?

Post by ahenry3068 »

funkheld wrote: Mon Mar 25, 2024 3:56 pm Thanks for the info.

Vera etc. requires data with vpoke as 1 byte, hibyte and lobyte. That means you don't have to worry about that if you take poke/vpoke.
you just pass the number/value?

Thanks.
greeting
Yes with Poke or Vpoke valid values to Poke are 0 to 255. BASIC takes care of any necessary conversions. If you try to Poke a Negative number or a Number > 255 then BASIC will give you a "VALUE OUT OF RANGE" error.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: Are there integer numbers in the basic of x16 please?

Post by funkheld »

hello thanks for help.

greeting
TomXP411
Posts: 1781
Joined: Tue May 19, 2020 8:49 pm

Re: Are there integer numbers in the basic of x16 please?

Post by TomXP411 »

Slevin wrote: Mon Mar 25, 2024 2:11 pm
ahenry3068 wrote: Mon Mar 25, 2024 2:00 pm Floats take 5 bytes per element.
Is this a proprietary floating point representation, or is the 5th byte reserved for some kind of meta data? At least according to the birth date of the IEEE 754 standard I assume that it must be proprietary in some kind, but 5 byte must have a requirement. Can someone eplain?
The floating point numbers share the same basic concept as IEEE-754, but the layout is different.

CBM has the exponent first, followed by the sign and mantissa.
CBM Float Exponent S Mantissa 0111 1111 0 0000 0000 0000 0000 0000 0000 0000 000 IEEE-754 Float S Exponent Mantissa 1 0111 1111 0000 0000 0000 0000 0000 000

With 31 bits available for the Mantissa, a CBM float can encode a full 32-bit signed value (approx. +/-2.4 billion) with no loss of precision.

Aside from that, the two systems use mostly the same basic logic for encoding values: The value in the mantissa is actually 1.0 to 1.9999999995343387126922607421875, although the 1 bit is implied. To get value other than fractions of 1, the mantissa is multiplied by the exponent, which is a power of 2.

Some examples:
2.0 = 1.0 * 2
3.0 = 1.5 * 2
5.0 = 1.25 * 4
2024 = 1.9765625 * 1024

The special cases are also slightly different:
$00 in the exponent is interpreted as 0, and the mantissa is ignored. (IEEE requires all 32 bits to be 0 to encode a 0.)
IEEE interprets an exponent of $FF as Infinity, and $FF + any mantissa as NaN (Not a Number). CBM floats do not have either encoding.

So other than the special cases, it's fairly easy to convert CBM floats to IEEE floats:
Copy CBM bit 8 (sign) to IEEE bit 0.
Copy CBM bits 0-7 to IEEE bits 1-8
Copy CBM bits 9-31 to IEEE bits 9-31

To copy an IEEE float to a CBM float, just reverse the above process, then clear the rightmost 8 bits.
skaratso
Posts: 7
Joined: Mon Jan 08, 2024 1:37 am

Re: Are there integer numbers in the basic of x16 please?

Post by skaratso »

ahenry3068 wrote: Mon Mar 25, 2024 2:15 pm
Slevin wrote: Mon Mar 25, 2024 2:11 pm
ahenry3068 wrote: Mon Mar 25, 2024 2:00 pm Floats take 5 bytes per element.
Is this a proprietary floating point representation, or is the 5th byte reserved for some kind of meta data? At least according to the birth date of the IEEE 754 standard I assume that it must be proprietary in some kind, but 5 byte must have a requirement. Can someone eplain?
Its modified by Commodore

Commodore uses a variant of IEEE-754 Floating point numbers. The short version is that BASIC stores the number using 5 bytes. 4 bytes hold the significant digits (31 binary digits, plus a sign) and 1 byte holds the exponent, aka the number of places to move the decimal point.Sep 30, 2018

Commodore BASIC Integer Size - Lemon64

Lemon64
https://www.lemon64.com
It's not technically "modified," as it predates the IEEE standard by at least 4 years (it looks like the IEEE 754 standard was first published in a proposal dated 1981 and then ratified in 1985), and Microsoft is responsible for the 5 byte floating point representation since the same format is used in both Commodore BASIC and Applesoft BASIC. Indeed, Commander X16 BASIC, being derived from Commodore BASIC V2 from the Commodore 64, shares the same flaws in its floating point arithmetic as the Apple II does. Here is an article about those flaws in Applesoft BASIC. The code examples given function identically (with a few exceptions).

https://archive.org/details/Apple_2_App ... P/mode/2up
Post Reply