Dim variable c% as Double

colin9876

Active Member
Licensed User
Typing a variable as an Integer is something we have chatted about before.

Basic4ppc is ingenious in the way it parses the code so it can run through the Micro$oft C compiler, but it stores all vars as strings which get converted if they are numbers;

So anything like c=c+1 involves transformations from variable held as string into number then back again!

In speed critical routines Ive used c(0)=c(0)+1 because you can type arrays as integers

In version 6.4 can we have a neater way to do simple typing. My suggestion would be that any var ending in the percent sign is stored as a Double and then the conversion routines can be omitted by the parser.

e;g; c%=c%+1
This will give faster, more compact code and fits with Basic conventions that % represents a numerical variable.

p.s; Basic4ppc is great - this addition will make it near perfect! lol!
 
Last edited:

agraham

Expert
Licensed User
Longtime User
In My suggestion would be that any var ending in the percent sign is stored as a Double and then the conversion routines can be omitted by the parser
To be pedantic (yet again :) !) it should be a # which is historic Basic for a double, % was used for 16 bit integers. But yes I would like that too even if it only worked in optimised compile and was treated like a normal variable in IDE/legacy compile.
 

colin9876

Active Member
Licensed User
variable#

Great Im all for keeping with convention
number# would be fine

So how about it Erel, when I asked last year u said u would think about it?

It would be much faster and neater for numerical operations - if u look at the generated C code a fair chunk of the processor work is converting number strings into doubles then back again into strings!
 
Last edited:

colin9876

Active Member
Licensed User
faster!

Just for the record unlike some of you pureists - Im not a fan of TYPEing for the sake of it, its just for speed reasons (the PPCs are still not fast with some programs, and all those extra calls to the conversion routines slow it down more)

Apart from the speed advantage - I cant see any advantage in TYPEing variables (especially for all u desktop guys who rarely actually run these codes on the slower ppc devices anyway lol)

Is there any advantage that Im missing apart from the speed?

I still hope that TYPEing variables will be optional, as I may only bother declaring them as numbers etc in speed critical loops etc
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Is there any advantage that Im missing apart from the speed?
It is less important than in the old days but memory usage was an issue so you used the smallest numeric type that offered the range of values needed. Also in the old days floating point ops were either done in software or in slower (than integer ops) hardware and as the machines were much slower overall performance suffered so you used integer working wherever possible.

Incidentally the main advantage that early supercomputers had came from their ability to do multiple floating point operations in parallel, known as vector processing. They were not necessarily much faster per se than ordinary (scalar processing) mainframes but had an architecture better suited to number crunching.

Types also offer code safety, especially if you can declare you own types. You cannot then assign an apple to an orange. This is less important coding by yourself but more important when working as part of a team. Also you can only do operations on a type that are supported by that type, so you can't add Booleans for example.

I am an advocate of strong typing (as long as a way round it exists when required!) but then I am also weird in that I dislike operator precedence and like to parenthesise my expressions so that they don't rely on it!
 
Top