Standard Data Type Limits

Forum for discussion about the documentation project.
Post Reply
Flyzone
Posts: 109
Joined: Nov 17, 2017 17:39

Standard Data Type Limits

Post by Flyzone »

Shouldn't the BOOLEAN type be listed here?

https://www.freebasic.net/wiki/TblVarTypes
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Standard Data Type Limits

Post by fxm »

Without considering the implementation under the hood (one byte), a FreeBASIC Boolean contains only two values: False or True, as viewed by a user.
For compatibility with other languages, FreeBASIC allows conversion without warning of only 3 numeric values -1 / 0 / + 1 to True / False / True respectively (so it is only a conversion).
A pure Boolean therefore has no limit values.
(a pure Boolean has only two states: False or True)
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Standard Data Type Limits

Post by jj2007 »

fxm wrote:For compatibility with other languages, FreeBASIC allows conversion without warning of only 3 numeric values -1 / 0 / + 1 to True / False / True respectively (so it is only a conversion).
A pure Boolean therefore has no limit values.
What do you mean?
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Standard Data Type Limits

Post by badidea »

A pure boolean is not a number (I think). You cannot make a range of sequential boolean values and no minimum and maximum limit.
Also, you cannot add or subtract booleans, see:

Code: Select all

dim as boolean a = true, b = true
print a + b 'type mismatch
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Standard Data Type Limits

Post by jj2007 »

Example from GfaBasic, with False=0 and True=-1:

Code: Select all

MyBool!=MID$(some$,3,1)="_"
Result$=LEFT$(some$,3+MyBool!)
So if some$ had the understroke, Result$ would be 2 chars long, otherwise 3. Since I wrote this stuff 30 years ago, my programming style has changed, but the example demonstrates that treating booleans as numbers can be useful in some cases.
Flyzone
Posts: 109
Joined: Nov 17, 2017 17:39

Re: Standard Data Type Limits

Post by Flyzone »

This is more academic and about taxonomy and complete documentation than anything and whether BOOLEAN is a "Data Type". You can't add letters either, but they are listed as a data type in the doc (though I'm certain someone will say that, technically, you can). It seems to me the only one missing is BOOLEAN. It is a data type (IMHO), requires a defined amount of storage, can be read, stored, moved and even used in a computation. Is it an 8 bit format with only two "values" or should it be defined some other way?
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Standard Data Type Limits

Post by fxm »

See the BOOLEAN documentation page, updated in the wiki:
- Under the hood, a FreeBASIC boolean is implemented as a 1-bit wide data (but in a byte) that allows to code the boolean value (0=>False, 1=>True).
- Seen from the user, a FreeBASIC boolean has only 2 values: False or True.
- Otherwise, when assigning a boolean with an integer value (by implicit conversion and not with the False or True value), '0' induces the False state and '1' or '-1' induces the True state (any other value also induces the True state, but with a warning message).
- Otherwise when assigning a numeric type with a boolean (by implicit conversion), False induces the '0' value and True induces the '-1' value.

See also:
- TblVarTypes → fxm [added Boolean type]
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: Standard Data Type Limits

Post by Munair »

jj2007 wrote:
fxm wrote:For compatibility with other languages, FreeBASIC allows conversion without warning of only 3 numeric values -1 / 0 / + 1 to True / False / True respectively (so it is only a conversion).
A pure Boolean therefore has no limit values.
What do you mean?
I think he means that boolean is either zero or non-zero (indicated by 1 or -1), whereas other numeric types such as a byte has limits (positive 127 signed and 255 unsigned.
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: Standard Data Type Limits

Post by speedfixer »

Interesting that it WAS in that table, and now removed. WHY? WHEN?
With no discussion, again? Who is the dictator that makes these decisions with no discussion in the community?

There IS a range of values: true and false.

Not worth arguing this.
Someone thinks their logic is better than clarity and convenience for the users.

david
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Standard Data Type Limits

Post by fxm »

About TblVarTypes I guess:

What are you talking?
Nothing has been removed since I added the Boolean type.
I just recently moved up the Boolean type table before "Arrays" which seems logical (because we can also define Boolean arrays).

My mother always told me:
"You have to turn your tongue seven times in your mouth before speaking".
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: Standard Data Type Limits

Post by speedfixer »

Interesting quote.

I don't know what I was looking at, but I am wrong; you are correct.
I apologize; I am in error.

david
Post Reply