Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 18:44 17 May 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 : MMBasic for DOS. Ver 5.04 Beta

     Page 2 of 6    
Author Message
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1421
Posted: 09:59am 02 Jul 2017
Copy link to clipboard 
Print this post

  twofingers said  
Please look at the value of Pi.


Three-ish.
Micromites and Maximites! - Beginning Maximite
 
GoodToGo!

Senior Member

Joined: 23/04/2017
Location: Australia
Posts: 188
Posted: 01:18pm 02 Jul 2017
Copy link to clipboard 
Print this post

  CircuitGizmos said  
  twofingers said  
Please look at the value of Pi.


Three-ish.


Give or take a bit.
...... Don't worry mate, it'll be GoodToGo!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3167
Posted: 03:49pm 02 Jul 2017
Copy link to clipboard 
Print this post

New version (beta 2) with:
- Double precision for Pi
- The third parameter of the STR$() function can be negative indicating that exponential format must be used.

2017-07-03_014359_DOS_MMBasic_Ver_5.04.05_Beta_2.zip

Geoff
Geoff Graham - http://geoffg.net
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 04:12pm 02 Jul 2017
Copy link to clipboard 
Print this post

  Geoffg said  The third parameter of the STR$() function can be negative indicating that exponential format must be used.


is there any chance this addition could at some time be brought into the other versions of micromite basic too?


cheers,
rob :-)
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 05:37pm 02 Jul 2017
Copy link to clipboard 
Print this post

PI looks good now
  Quote   pie$=" 3.14159265358979323846264338327950288419716939937510582097494459230781640628"
PRINT pie$
PRINT STR$(PI,2,20)
PRINT STR$(PI,2,15)
PRINT PI


  Quote  DOS MMBasic Ver 5.04.05 Beta 2
Copyright 2011-2017 Geoff Graham

3.14159265358979323846264338327950288419716939937510582097494459230781640628
3.14159265358979311599
3.141592653589793
3.141592654


Using STR$(), the MMX limits decimal places to 16 compared to the DOS version's 20 places.
Anything more than 15 or 16 gives a false sense of precision.
Programmers will never learn the limits of floating point maths....

Jim
VK7JH
MMedit   MMBasic Help
 
cdeagle
Senior Member

Joined: 22/06/2014
Location: United States
Posts: 261
Posted: 10:51pm 02 Jul 2017
Copy link to clipboard 
Print this post

Thanks for creating the new beta Geoff.
 
cdeagle
Senior Member

Joined: 22/06/2014
Location: United States
Posts: 261
Posted: 12:11am 03 Jul 2017
Copy link to clipboard 
Print this post

I'm getting the following error when running the DOS version of solar_eclipse.bas. I do not get this error when running the program on the MMX or Raspi.

[3146] Print "calendar date ", month$(cmonth) + " " + Str$(Int(day)) + " " + Str$(year)
Error: String too long

I tried changing the statement that defines the month$ array to

DIM month$(12) LENGTH 10 instead of DIM month$(12)

but still received this error.

 
cdeagle
Senior Member

Joined: 22/06/2014
Location: United States
Posts: 261
Posted: 12:20am 03 Jul 2017
Copy link to clipboard 
Print this post

A bit of debug information for the "String too long" error.

> print cmonth
6
> print month$(6)
June
> print day
23.45268715
> print int(day)
23
> print str$(int(day))
Error: String too long
 
cdeagle
Senior Member

Joined: 22/06/2014
Location: United States
Posts: 261
Posted: 12:35am 03 Jul 2017
Copy link to clipboard 
Print this post

ATAN2 function missing from DOS version?

[744] gb = atan2(z, Sqr(x^2 + y^2))
Error: Dimensions
> print atan2(.5, .7)
Error: Function or array ATAN2 not declared
 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 08:28am 03 Jul 2017
Copy link to clipboard 
Print this post


  Quote  to get double precision output accurate without ...


I can see a small error in there... I'll detail it after/if after WW builds a
sn-7x
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3167
Posted: 09:30pm 03 Jul 2017
Copy link to clipboard 
Print this post

"String too long" error seems like a bug. Leave it with me and I will chase it down.

  cdeagle said   ATAN2 function missing from DOS version?

It was never in the standard MMBasic.

I'm not a maths expert but this is what I use:
Function atan2(y As float, x As float) As float
If x > 0 Then atan2 = Atn(y / x)
If x < 0 And y >= 0 Then atan2 = Atn(y /x) + Pi
If x = 0 And y > 0 Then atan2 = Pi / 2
If x < 0 And y < 0 Then atan2 = Atn(y / x) - Pi
If x = 0 And y < 0 Then atan2 = -Pi / 2
End Function


Geoff


Geoff Graham - http://geoffg.net
 
cdeagle
Senior Member

Joined: 22/06/2014
Location: United States
Posts: 261
Posted: 11:08pm 03 Jul 2017
Copy link to clipboard 
Print this post

Peter must have added ATAN2 to the MMX version of MMBASIC.

Thanks for the ATAN2 function code.
 
cdeagle
Senior Member

Joined: 22/06/2014
Location: United States
Posts: 261
Posted: 12:29am 04 Jul 2017
Copy link to clipboard 
Print this post

The "string too long" can be avoided by using code similar to

iday = int(day)

print "calendar date ", month$(cmonth) + " " + STR$(iday) + " " + str$(year)

Here's another version of ATAN2 that I found somewhere in my archives. I think it was ported from Oliver Montenbruck's PASCAL version.

function atan2(y, x) as float

' +/- pi inverse tangent function

' input

' y = sine of angle
' x = cosine of angle

' output

' atan2 = angle (-pi =< atan2 <= pi; radians)

''''''''''''''''''''''''''''''''''''''''''''''''

local ax, ay, phi

if (x = 0.0) and (y = 0.0) then

atan2 = 0.0

else

ax = abs(x)

ay = abs(y)

if (ax > ay) then

phi = atan(ay / ax)

else

phi = pidiv2 - atan(ax / ay)

end if

if (x < 0.0) then phi = pi - phi

if (y < 0.0) then phi = - phi

atan2 = phi

end if

end function

 
cdeagle
Senior Member

Joined: 22/06/2014
Location: United States
Posts: 261
Posted: 01:48am 04 Jul 2017
Copy link to clipboard 
Print this post

My bad.

All occurrences of atan in my previous post for the atan2 function should be atn.
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 03:52am 04 Jul 2017
Copy link to clipboard 
Print this post

i always reckon ATAN is far more intuitive than ATN

geoff: how practical would it be for the tokenizer to recognize both ATAN and ATN, converting them to the same single token? when launched, the editor could then de-tokenize to the far superior ATAN. this would effectively introduce an automatic conversion.

the same could be applied to DS18B20 and TEMPR, DHT22 and HUMID, while TRON and TROFF could be automatically replaced with TRACE ON|OFF.

in all, this would free up four tokens. ATN, DS18B20, DHT22, TRON, and TROFF would remain reserved words, but be automatically translated to their alternatives.


cheers,
rob :-)
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3167
Posted: 03:16pm 04 Jul 2017
Copy link to clipboard 
Print this post

ATN is used in Microsoft BASIC and I try to keep compatible with that wherever possible (blame Bill if you do not like it).

Another issue is pollution of the name space - a big issue for anyone defining languages and APIs. Duplicate keywords might make sense to you and me (and might make cdeagle's day a little easier) but alternative names for the same thing just clutter up the language. By the way, DS18B20, DHT22, TRON, TROFF, etc will simply be removed in the future.

However, the tokeniser already does a similar job, for example it will automatically convert END IF to ENDIF (too many people could not remember which one to use). So, it would be simple to create duplicate keywords. I will do some head scratching and think about the ramifications.

In the meantime, here is beta 3 which fixes the "String too long" bug when an integer was used in STR$(): 2017-07-05_011401_DOS_MMBasic_Ver_5.04.05_Beta_3.zip

GeoffEdited by Geoffg 2017-07-06
Geoff Graham - http://geoffg.net
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 04:15pm 04 Jul 2017
Copy link to clipboard 
Print this post

When I played with ATN2 a few years ago, I had problems as x approached zero.

This function is the same as Geoff's but a test for small values of x

  Quote  FUNCTION atn2(y,x)
IF ABS(x) < 0.0000001 THEN
arctan =
0
x =
0
ELSE
arctan =
ATN(y/x)
ENDIF
IF x > 0 THEN
atn2 = arctan
ELSEIF y>=0 AND x<0 THEN
atn2 =
PI + arctan
ELSEIF y< 0 AND x<0 THEN
atn2 = arctan -
PI
ELSEIF y> 0 AND x=0 THEN
atn2 =
PI / 2
ELSE ' y< 0 and x=0
atn2 = PI / -2
ENDIF
END FUNCTION

It was written for 32 bit floating point. The issue will not be such a problem with 64bit but in theory, it could still be there to catch you.

Jim

VK7JH
MMedit   MMBasic Help
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 04:18pm 04 Jul 2017
Copy link to clipboard 
Print this post

basic on sharp pocket computers (PC-1211, etc) run microsoft basic and use ATAN, so it is not totally universal either way - an automatic translation would seem to be a way to keep everyone happy. as for TRON and TROFF, i'd be equally happy to see them just removed.

one thing i have been mulling over is the idea of 16-bit tokens, could this save on the flash space required to store the user program? with 65000 tokens available it may be possible to also then translate variable names into 'dynamic tokens', which may speed up the interpreter considerably as there would then be no need to interpret any plain text while a program is running. note: this is just a vague idea, not a suggestion for the immediate future!


cheers,
rob :-)Edited by robert.rozee 2017-07-06
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3167
Posted: 06:00pm 04 Jul 2017
Copy link to clipboard 
Print this post

Jim, in your code is arctan a global variable? It is not defined.

Also, where you use x = 0 that could be dangerous. If someone used a variable for the argument it would be passed by reference and set to zero.

GeoffEdited by Geoffg 2017-07-06
Geoff Graham - http://geoffg.net
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 07:16pm 04 Jul 2017
Copy link to clipboard 
Print this post

arctan should be declared as a LOCAL.
and thanks for the warning about passing by reference.
I don't think I need the x=0 there at all. The function was developed when there was some work on distance and bearing between locations. There were errors when almost due north etc.

Jim
VK7JH
MMedit   MMBasic Help
 
     Page 2 of 6    
Print this page
© JAQ Software 2024