QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: SMcNeill on October 30, 2018, 12:02:20 pm

Title: QB64 CONST completely overhauled
Post by: SMcNeill on October 30, 2018, 12:02:20 pm
So I couldn't sleep last night, so I completely updated CONST and our internal math routines...

Bug here is fixed:  https://www.qb64.org/forum/index.php?topic=703.0

********************

You can now use CONST with our math routines.  Before, the following would error out for us:

CONST X = 1.2
CONST Y = INT(X)

Now, QB64 handles those routines just fine with the extended math functions.

**********************

The math routine got overhauled.  Originally, the math functions to CONST were added several months BEFORE they were added into the main language itself.  They were drafted into purpose from my experimental SteveIDE, and didn't match our standard naming convention.

Believe it or not, CONST X = ARCCOS(0.5) used to work just fine for us.  (Unless I've got the name wrong...)

QB64, however, works with _ACOS, as that was the name the community decided on when the command was added into the language...

So, to correct this issue, I've changed the names you can use in CONST so they now match the actual syntax for the language.

********************

Several thousand lines of SteveIDE-related error-checking was removed, leaving QB64.bas and QB64.exe both smaller by quite a bit.

********************

Grab a copy of the Github version I forked off for the changes, and test to see if anything freezes, errors out, or returns false results.  If all works as it should, the changes can be merged into the main repo soon and everyone can enjoy these fixes/enhancements.
Title: Re: QB64 CONST completely overhauled
Post by: SMcNeill on October 30, 2018, 12:09:42 pm
Functions which we can now use with CONST:

Code: QB64: [Select]
  1.         CASE "_PI": n1 = 3.14159265358979323846264338327950288## 'Future compatable in case something ever stores extra digits for PI
  2.         CASE "%": n1 = (VAL(num(1))) / 100 'Note percent is a special case and works with the number BEFORE the % command and not after
  3.         CASE "_ACOS": n1 = _ACOS(VAL(num(2)))
  4.         CASE "_ASIN": n1 = _ASIN(VAL(num(2)))
  5.         CASE "_ARCSEC": n1 = _ARCSEC(VAL(num(2)))
  6.         CASE "_ARCCSC": n1 = _ARCCSC(VAL(num(2)))
  7.         CASE "_ARCCOT": n1 = _ARCCOT(VAL(num(2)))
  8.         CASE "_SECH": n1 = _SECH(VAL(num(2)))
  9.         CASE "_CSCH": n1 = _CSCH(VAL(num(2)))
  10.         CASE "_COTH": n1 = _COTH(VAL(num(2)))
  11.         CASE "COS": n1 = COS(VAL(num(2)))
  12.         CASE "SIN": n1 = SIN(VAL(num(2)))
  13.         CASE "TAN": n1 = TAN(VAL(num(2)))
  14.         CASE "LOG": n1 = LOG(VAL(num(2)))
  15.         CASE "EXP": n1 = EXP(VAL(num(2)))
  16.         CASE "ATN": n1 = ATN(VAL(num(2)))
  17.         CASE "_D2R": n1 = 0.0174532925 * (VAL(num(2)))
  18.         CASE "_D2G": n1 = 1.1111111111 * (VAL(num(2)))
  19.         CASE "_R2D": n1 = 57.2957795 * (VAL(num(2)))
  20.         CASE "_R2G": n1 = 0.015707963 * (VAL(num(2)))
  21.         CASE "_G2D": n1 = 0.9 * (VAL(num(2)))
  22.         CASE "_G2R": n1 = 63.661977237 * (VAL(num(2)))
  23.         CASE "ABS": n1 = ABS(VAL(num(2)))
  24.         CASE "SGN": n1 = SGN(VAL(num(2)))
  25.         CASE "INT": n1 = INT(VAL(num(2)))
  26.         CASE "_ROUND": n1 = _ROUND(VAL(num(2)))
  27.         CASE "FIX": n1 = FIX(VAL(num(2)))
  28.         CASE "_SEC": n1 = _SEC(VAL(num(2)))
  29.         CASE "_CSC": n1 = _CSC(VAL(num(2)))
  30.         CASE "_COT": n1 = _COT(VAL(num(2)))
  31.         CASE "^": n1 = VAL(num(1)) ^ VAL(num(2))
  32.         CASE "SQR": n1 = SQR(VAL(num(2)))
  33.         CASE "ROOT"
  34.             n1 = VAL(num(1)): n2 = VAL(num(2))
  35.             IF n2 = 1 THEN EvaluateNumbers$ = RTRIM$(LTRIM$(STR$(n1))): EXIT FUNCTION
  36.             IF n1 < 0 AND n2 >= 1 THEN sign = -1: n1 = -n1 ELSE sign = 1
  37.             n3 = 1## / n2
  38.             IF n3 <> INT(n3) AND n2 < 1 THEN sign = SGN(n1): n1 = ABS(n1)
  39.             n1 = sign * (n1 ^ n3)
  40.         CASE "*": n1 = VAL(num(1)) * VAL(num(2))
  41.         CASE "/": n1 = VAL(num(1)) / VAL(num(2))
  42.         CASE "\": n1 = VAL(num(1)) \ VAL(num(2))
  43.         CASE "MOD": n1 = VAL(num(1)) MOD VAL(num(2))
  44.         CASE "+": n1 = VAL(num(1)) + VAL(num(2))
  45.         CASE "-": n1 = VAL(num(1)) - VAL(num(2))
  46.         CASE "=": n1 = VAL(num(1)) = VAL(num(2))
  47.         CASE ">": n1 = VAL(num(1)) > VAL(num(2))
  48.         CASE "<": n1 = VAL(num(1)) < VAL(num(2))
  49.         CASE "<>", "><": n1 = VAL(num(1)) <> VAL(num(2))
  50.         CASE "<=", "=<": n1 = VAL(num(1)) <= VAL(num(2))
  51.         CASE ">=", "=>": n1 = VAL(num(1)) >= VAL(num(2))
  52.         CASE "NOT": n1 = NOT VAL(num(2))
  53.         CASE "AND": n1 = VAL(num(1)) AND VAL(num(2))
  54.         CASE "OR": n1 = VAL(num(1)) OR VAL(num(2))
  55.         CASE "XOR": n1 = VAL(num(1)) XOR VAL(num(2))
  56.         CASE "EQV": n1 = VAL(num(1)) EQV VAL(num(2))
  57.         CASE "IMP": n1 = VAL(num(1)) IMP VAL(num(2))
Title: Re: QB64 CONST completely overhauled
Post by: STxAxTIC on October 30, 2018, 12:37:41 pm
Apologues for not "properly" looking this up yet but it may be useful - can we see the entire EvaluateNumbers$ function for our edification?
Title: Re: QB64 CONST completely overhauled
Post by: SMcNeill on October 30, 2018, 12:56:35 pm
Apologues for not "properly" looking this up yet but it may be useful - can we see the entire EvaluateNumbers$ function for our edification?

Sure.  Just look in QB64.bas.  ;D

Actually, that's almost the whole function anyway, though it's just a part of the system which we use with EvaluateExpression$.  There's one section which sets our order of precedence.  Another to translate for &B, &H, and scientific notation.  There's one routine which deals with duplicate negatives...  EvaluateNumbers in just the cog in the machine which actually does the math functions for us.  I was just lazy and posted the code as an easy way to highlight the functions currently available for us. 
Title: Re: QB64 CONST completely overhauled
Post by: bplus on October 30, 2018, 01:08:59 pm
Thanks Steve, that is one thing I have wanted for some time, myself.

This is in latest download now? Oh it is forked off I see, OK!
Title: Re: QB64 CONST completely overhauled
Post by: SMcNeill on October 31, 2018, 08:12:03 am
Pushed the changes here into the development build for us, so folks will have it a little easier downloading and testing.  So far, all seems to work as advertised, and this will make it one step easier for everybody to take advantages to these changes/bug fixes sooner. 
Title: Re: QB64 CONST completely overhauled
Post by: doppler on October 31, 2018, 09:24:02 am
@SMcNeill Got to get a hobby.  And I don't mean QB64.

Typical programmer.  Gut the code make it smaller, faster and add options/features.

For your next event are you going to pull a rabbit out of a hat or walk on water ?
Walking on water is easy, just need a submerged plank one inch below the water line.
Title: Re: QB64 CONST completely overhauled
Post by: SMcNeill on October 31, 2018, 09:41:31 am
@SMcNeill Got to get a hobby.  And I don't mean QB64.

Typical programmer.  Gut the code make it smaller, faster and add options/features.

For your next event are you going to pull a rabbit out of a hat or walk on water ?
Walking on water is easy, just need a submerged plank one inch below the water line.

And pulling a rabbit out of a hat isn't hard either; it's putting them INTO the hat where they'll bite you!
Title: Re: QB64 CONST completely overhauled
Post by: Qwerkey on October 31, 2018, 12:24:40 pm
Excellent, Steve, as we expect.

As I only ever download specific QB64 versions, I shall eagerly await 1.3
Title: Re: QB64 CONST completely overhauled
Post by: Cobalt on October 31, 2018, 01:01:32 pm
And pulling a rabbit out of a hat isn't hard either; it's putting them INTO the hat where they'll bite you!

Keeping them from Poopin and\or Peein on you while you wear the hat is tricky too.
Title: Re: QB64 CONST completely overhauled
Post by: Pete on October 31, 2018, 04:54:48 pm
Funny, when I can't sleep at night, I just end up having sex... but my wife tells me I haven't spent enough time debugging that, either.

Pete :D

- I'm a CONST something.
Title: Re: QB64 CONST completely overhauled
Post by: TempodiBasic on October 31, 2018, 05:09:38 pm
Steve
great evolution!
thank to use so your time!
I'm sorry about your insomnia! But I can see that you are able to turn in positive some negative events.

Good!
Title: Re: QB64 CONST completely overhauled
Post by: bplus on November 02, 2018, 12:26:12 pm
Hi Steve,

I am wondering if CONST can do _RGB32() like other math functions?
Title: Re: QB64 CONST completely overhauled
Post by: SMcNeill on November 02, 2018, 12:28:18 pm
Hi Steve,

I am wondering if CONST can do _RGB32() like other math functions?

It can.  That's something that hasn't changed. It's just handled in a different routine than the one which I posted from above.  ;)

It also handles _RGB colors, but it treats the 4th parameter as a screen mode rather than as an image handle.
Title: Re: QB64 CONST completely overhauled
Post by: bplus on November 02, 2018, 12:38:38 pm
Hi Steve,

I am wondering if CONST can do _RGB32() like other math functions?

It can.  That's something that hasn't changed. It's just handled in a different routine than the one which I posted from above.  ;)

It also handles _RGB colors, but it treats the 4th parameter as a screen mode rather than as an image handle.

Dang why did I think it didn't, must have been alpha I was trying.

Thanks!
Title: Re: QB64 CONST completely overhauled
Post by: SMcNeill on November 02, 2018, 12:41:27 pm
_RGBA and _RGBA32 both work as well.  (Or at least they should, unless something is broken.)
Title: Re: QB64 CONST completely overhauled
Post by: FellippeHeitor on November 02, 2018, 01:07:18 pm
There are new syntaxes for _RGB32 in the dev build, that's likely what bplus means.
Title: Re: QB64 CONST completely overhauled
Post by: bplus on November 02, 2018, 01:18:48 pm
Hi Fellippe,

No, I do know about those updates. But does not hurt to remind! :)

Some time ago I seem to remember trying to setup color constants and ran into difficulties using _RGB something and figured it was because I was using a function so I switched to &H.... and that did work.

It's even possible I have used _RGB something for setting up color constants because it is my first instinct.

Eh memory, I don't think it will get better.