Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 05:35 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : numbers on MM

     Page 1 of 2    
Author Message
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 02:19pm 20 Jul 2012
Copy link to clipboard 
Print this post

I am wondering, how numbers are used in MMBasic?
The description says floating-point is always used, so
I guess a zero exponent is used to allow integer-type values
and the 23 or 24 bits gives a maximum of 16 million or so in scope.
Is the range -8 to 8 million, or 0 to 16 million ?
Also, 23 or 24 bit fp runs out of precision at about 7 significant
figures eg ppm, is MMBasic the same ?


 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 04:54pm 20 Jul 2012
Copy link to clipboard 
Print this post

Here is a quote from page 8 of the MMBasic Manual V3.2
Implementation Characteristics
Maximum length of a command line is 255 characters.
Maximum length of a variable name or a label is 32 characters.
Maximum number of dimensions to an array is 8.
Maximum number of arguments to commands that accept a variable number of arguments is 50.
Maximum number of user defined subroutines and functions (combined): 64
Numbers are stored and manipulated as single precision floating point numbers. The maximum number that
can be represented is 3.40282347e+38 and the minimum is 1.17549435e-38
The range of integers (whole numbers) that can be manipulated without loss of accuracy is ±16777100
Maximum string length is 255 characters.
Maximum line number is 65000.
Maximum length of a file pathname (including the directory path) is 255 characters.
Maximum number of files simultaneously open is 10 on the SD card and one on the internal flash drive (A:).
Maximum SD card size is 2GB formatted with FAT16 or 2TB formatted with FAT32.
Size of the internal flash drive (A:) is 212KB.
Maximum size of a loadable video font is 64 pixels high x 255 pixels wide and 256 characters.
Edited by BobD 2012-07-22
 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 08:38pm 20 Jul 2012
Copy link to clipboard 
Print this post

Thanks,
I looked for more large-integer info, the updated software library
is said to contain a program example "bigint" but I could
not see it. There is also a remark about the next step
being to put in negative numbers, so there is a discrepancy (?).
The reason I ask, is that I am wondering about trying assembler on
the dspic32, if my memory is right the MIPS core etc provides some
native floating point instructions which would have been usedEdited by chronic 2012-07-22
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3801
Posted: 11:59pm 20 Jul 2012
Copy link to clipboard 
Print this post

I believe MMBasic just uses what the raw chip gives you (via C libs, when used).

So, consult Microchip PIC32 family doc.

John
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 01:28am 21 Jul 2012
Copy link to clipboard 
Print this post

Yes, the PIC32 implementation of the MIPS architecture does not have built in floating point. So MMBasic uses the Microchip compiler libraries which are single precision floating point meeting the IEEE-754 standard.

Geoff
Geoff Graham - http://geoffg.net
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 01:59pm 21 Jul 2012
Copy link to clipboard 
Print this post

  chronic said   Thanks,
I looked for more large-integer info, the updated software library
is said to contain a program example "bigint" but I could
not see it. There is also a remark about the next step
being to put in negative numbers, so there is a discrepancy (?).


Back in February, I wore a program to do big integers in MM Basic.

http://www.thebackshed.com/forum/forum_posts.asp?TID=4653&PN =13
Being in Basic, it is very slow but it was only an exercise to prove that it could be done.

Jim
VK7JH
MMedit   MMBasic Help
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 07:34pm 22 Jul 2012
Copy link to clipboard 
Print this post

  TassyJim said  
  chronic said   Thanks,
I looked for more large-integer info, the updated software library
is said to contain a program example "bigint" but I could
not see it. There is also a remark about the next step
being to put in negative numbers, so there is a discrepancy (?).


Back in February, I wore a program to do big integers in MM Basic.

http://www.thebackshed.com/forum/forum_posts.asp?TID=4653&PN =13
Being in Basic, it is very slow but it was only an exercise to prove that it could be done.

Jim


My apologies to TassyJim and Chronic. BIGINT never did get into the library, except in the Readme notes. It will be in the next library update.

Cheers,
Hugh
 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 08:58pm 23 Jul 2012
Copy link to clipboard 
Print this post

Thanks.
Last question : can a variable somehow be declared as datatype integer ?
I thought that was a standard part of some Basic variants,
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3801
Posted: 10:20am 24 Jul 2012
Copy link to clipboard 
Print this post

It will be and stay an integer if you keep within certain limits and avoid assigning a number with a fractional part. Maybe that will do?

John
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 01:25pm 24 Jul 2012
Copy link to clipboard 
Print this post

  chronic said   Thanks.
Last question : can a variable somehow be declared as datatype integer ?
I thought that was a standard part of some Basic variants,


Short answer is NO.

Back when computers were very slow, having integer maths was needed but now that the processor has a lot more speed and maths functions built in, the need for integer maths is not there.

It makes things easier if you don't have to think about different types and converting between the two (or more).

MMBasic is all in floating point with about 7 digits of precision.


Jim

VK7JH
MMedit   MMBasic Help
 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 04:45pm 24 Jul 2012
Copy link to clipboard 
Print this post

  TassyJim said   the need for integer maths is not there.
Jim


!! Uh, no way. That is a whole different topic that I'm not
continuing,
thanks and ciao.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3801
Posted: 09:55pm 24 Jul 2012
Copy link to clipboard 
Print this post

Why not say why you want integer variables?

John
 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 12:49am 25 Jul 2012
Copy link to clipboard 
Print this post

My concern is/was, if say (in most systems)
a is assigned a value eg
a = 10
then it may be stored and used using a binary integer, however if
b = 10.1 - 0.1
answer b uses a (very close) approximation..
so

a is not equal to b

which is (gee) why integer and real/floating point variables are
used differently.

The 16 million figure interested me because Microchip floating point
usually uses (after the sign and exponent bits) 23 bits for the storage plus another implied bit, I was thinking of the 23 bits only which would mean less than the 16 million.

...eof...
Edited by chronic 2012-07-26
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3801
Posted: 10:43am 25 Jul 2012
Copy link to clipboard 
Print this post

You asked about integer variables so you naturally would not be using 10.1 with one of those! If you want to do integer calculations or convert a floating point one to integer, you can. (Just think and do it.)

If you want to do things the equivalent of 10.1 - 0.1 then on pretty much any modern computer you're asking for specific behaviour (whether you realise it or not). If you want to avoid the sorts of problems you're hinting at then do the task properly i.e. round or truncate etc as you need.

As Geoff says, MMBasic uses what the C compiler/libs give you (again, true for pretty much any modern CPU). There are standard ways to figure out what that is if you can't find adequate documentation.

Unless you rush into calculations without thought none of this is likely to be a big problem. If you're doing serious numerical stuff, probably best not to use Basic - but honestly who is doing that and would?

John
 
darthmite

Senior Member

Joined: 20/11/2011
Location: France
Posts: 240
Posted: 11:00am 25 Jul 2012
Copy link to clipboard 
Print this post

From Maximite Basic doc.

FIX( number )
Truncate a number to a whole number by eliminating the decimal point
and all characters to the right of the decimal point.
For example 9.89 will return 9 and -2.11 will return -2.
The major difference between FIX and INT is that FIX provides a true
integer function

Have you try it ?
Edited by darthmite 2012-07-26
Theory is when we know everything but nothing work ...
Practice is when everything work but no one know why ;)
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:26pm 25 Jul 2012
Copy link to clipboard 
Print this post

True integers would be good for speed (games) and bit operations (video, IO etc).
A computer that uses a lot of connections to the real world with IO ports could really benefit from unsigned integer and byte datatypes.
And as C already provide those as many other datatypes it is only a choice by the maker. And it is open source so if it is really necessaary to have it just make it.
Edited by TZAdvantage 2012-07-27
Microblocks. Build with logic.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3801
Posted: 09:40pm 25 Jul 2012
Copy link to clipboard 
Print this post

To a fair extent, they would make no difference in MMBasic because it's an interpreter. Most of the overhead is there.

It's already the case that if a variable happens to be an integer then operations are faster because the compiler/libs are faster in such cases. Hardly measurable because of the interpreter overhead.

If you really want more speed you use a compiler or something in between (semi-compiler, goes by several other names).

Actually, for many years the way you get more speed has been just to use a faster CPU!

(And more memory, which tends to help.)

John
 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 07:02pm 26 Jul 2012
Copy link to clipboard 
Print this post

For the record, my example before was in response to the question

  JohnS said   Why not say why you want integer variables?

John


The SC article says MMB "is a full implementation of Basic" , hence my
questions, as things like GW Basic had many datatypes.
I was checking my recollections, as it is at least 25 years since I used Basic (and that was for a few hours at most); I certainly agree it is
not a good vehicle for quantitative work - it was not intended to be.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 05:26am 27 Jul 2012
Copy link to clipboard 
Print this post

  JohnS said   To a fair extent, they would make no difference in MMBasic because it's an interpreter. Most of the overhead is there.

It's already the case that if a variable happens to be an integer then operations are faster because the compiler/libs are faster in such cases. Hardly measurable because of the interpreter overhead.

If you really want more speed you use a compiler or something in between (semi-compiler, goes by several other names).

Actually, for many years the way you get more speed has been just to use a faster CPU!

(And more memory, which tends to help.)

John

:)
A faster CPU and more memory is the lazy way out. :)
In my opinion it is what caused the current sloppyness in what people program, in microcontrollers it is still oke because of the constrains, in pc software it is becoming a serious problem. Optimizing for speed is unknown to at least two generations of programmers. Something i have to deal with every day. Just as an example, we needed a program that processes short messages very fast, very fast in my world is around 50000 per second, in many others it is 500, especially when they start talking msmq and the sorts, brrrr the horrors. :)

With an interpreter the difference is actually greater because of the casting that is needed.
Casting in basic using int() i mean. In games they can greatly improve speeds up to hundreds of percents because many times games use very tight loops and counters.
Increasing just by one and then testing that value is done thousands of times per second.

Well, nothing is stopping anyone to add that functionality to mmbasic. I might even try int one day, although i have set my own personal challenge to make a javascript interpreter for the mm, making the whole thing essentially event driven.

Microblocks. Build with logic.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3801
Posted: 12:16am 28 Jul 2012
Copy link to clipboard 
Print this post

It would be easy to argue that using any version of Basic is the lazy way out!

BTW, Int() isn't really a cast in Basic (or most languages), it's a function.

Using Int() isn't going to slow things much or indeed help make the rest of the code faster, because it's an interpreter.

If you added integer variables to MMBasic I expect you'd find hardly any speed increase. Save your energies for something else!

John
 
     Page 1 of 2    
Print this page
© JAQ Software 2024