Author Topic: QB64 CONST completely overhauled  (Read 6259 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
QB64 CONST completely overhauled
« 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 CONST completely overhauled
« Reply #1 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))
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: QB64 CONST completely overhauled
« Reply #2 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?
You're not done when it works, you're done when it's right.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 CONST completely overhauled
« Reply #3 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. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 CONST completely overhauled
« Reply #4 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!
« Last Edit: October 30, 2018, 01:11:47 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 CONST completely overhauled
« Reply #5 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. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: QB64 CONST completely overhauled
« Reply #6 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.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 CONST completely overhauled
« Reply #7 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!
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: QB64 CONST completely overhauled
« Reply #8 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

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: QB64 CONST completely overhauled
« Reply #9 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.
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: QB64 CONST completely overhauled
« Reply #10 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.
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: QB64 CONST completely overhauled
« Reply #11 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!
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 CONST completely overhauled
« Reply #12 on: November 02, 2018, 12:26:12 pm »
Hi Steve,

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

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 CONST completely overhauled
« Reply #13 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 CONST completely overhauled
« Reply #14 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!