UnderwareDESIGN

PlayBASIC => Show Case => Topic started by: kevin on July 20, 2020, 08:31:54 AM

Title: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on July 20, 2020, 08:31:54 AM

(http://www.underwaredesign.com/forums/PlayBASIC-MATH64-200p.png)


PlayBASIC Math 64 - 64Bit Scripting LILbrary




Releases


         PlayBASIC Math64  V010 - Public Test   (2021-04-17) (https://www.underwaredesign.com/forums/index.php?topic=4535.msg30231#msg30231)
          PlayBASIC Math64  V009 - Public Test  (2021-02-05) (https://www.underwaredesign.com/forums/index.php?topic=4535.msg30164#msg30164)





Blog





 Ok.. PlayBASIC coders ..  interested in a 64Bit math library ??   We used to have one, but it's lost..  So lets make another one..



 Update:


     Just putting this together as a sort of secondary unit that can do Float64 math operations within it's own mini VM.     So the idea being is you have a variable table and then write the opcodes into memory with the variable offsets and then call the solver.    Much like the Vector unti experiment some years back.  


    Here's the current test code.  It's running in PB1.65, but it should run in 1.64 editions also..  at least in the short term

    Since this lives outside of the PB parser, we use strings to encode float64 values,  see example bellow.  



[pbcode]

      Dim VariableTable(1024)

      for lp= 0 to 10   
         PB64_StringToF64(Readdata$(),PtrToVar(lp))
         print PB64_F64ToString(PtrToVar(lp))
      next      

      Sync
      waitkey

      //  Some Sample 64 bit strings
      Data " 01234567890123456789"
      Data "01.234567890123456789"
      Data "012.34567890123456789"
      Data "0123.4567890123456789"
      Data "01234.567890123456789"
      Data "012345.67890123456789"
      Data "0123456.7890123456789"
      Data "01234567.890123456789"
      Data "012345678.90123456789"
      Data "0123456789.0123456789"
      Data "01234567890.123456789"
      Data "012345678901.23456789"
      Data "0123456789012.3456789"



[/pbcode]



Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: stevmjon on July 20, 2020, 08:59:58 PM
since we used to have one, may as well make a new one. might come in handy.
Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on July 20, 2020, 09:36:39 PM

  Well, there is the Extended Float library which is tucked away at the end of the LIBs forum,  And does seem to still be here..    Might just drop it into the slibs folder anyway just in case.


[plink]Extended Floating Point Library (https://www.underwaredesign.com/forums/index.php?topic=904.0)[/plink] (November 30, 2005)


 
Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on July 22, 2020, 11:05:49 AM
   PB Math64 vs  Extended Math

      I'd actually assumed the extended math was one of the lost libraries,  of which there are a few from the early days of PB (2003->2006/7)   sort of era.    Glad it's still here, but after looking it's implementation is not that quick to execute at runtime,   Given than each operation is performed by a externally DLL call.   Which is fine, but the call over head from the runtime side is way higher than the operation in this case.    

      So a better idea is to build a solver, or a mini runtime that just performs 64 bit math.   Initially I was think of a simple assembly styled interface were we'd have a simple script and it's lex and parse/convert that into the solvers opcodes.   So basically how the vector library worked.   But it might be better to do that n the library side so things are synchronous.    So the lexer and it's runtime are the same version.   What could happen is they'd they misaligned and the parser would generate the wrong opcodes for the run time.  


        Math64 Assembly

        Var A,B,C   ; Declare three 64 bit variables

        Add A ,B,C  ; A=B+C
        Sub A ,B,C  ; A=B-C
        Div  A ,B,C  ; A=B/C
        Mult A ,B,C  ; A=B*C




        You prolly could roll out single operation parser just a easy tho

     You still need to define your variables manually tho, which would be a stack made up of purely 64bit values  These are floats by the way,  the Idea here is to solve those situation were high precision is required.     The more operations you stacked, the better than gain over extended math library.


    For the time being this is novelty (like most things) but If we can get the method sorted then this opens doors to other impossible extensions..  

   



Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on July 23, 2020, 10:19:31 PM
    PB Math64 - Lexical Scanner -> Parser


      So had a go at this last night and have decided to embed to have a go at a sort of reduce functionality parser.    This means something can the user can declare variables in and perform operations and limited 64 maths  upon, but that's about it.  

      So the syntax is basically PB syntax but there's only a single data type..  64bit floats,  so to declare a variable at this point i've used VAR, but DIM / LOCAL would equally do.   It'll treat each line separately,  so the parser just falls through expecting everything to map to a line.    


Var A,B,C,D
Var Result

A=123
B=456
C=999999

Result=((A+B)/C)




      Picture bellow we pass this to the lexer and display the results on the Pb side.      

[pbcode]
function TestParser()
   
      Eol$=chr$(13)+chr$(10)

      Code$=""
      Code$+=" Var A,B,C,D"      +eol$
      Code$+=" Var Result"         +eol$
      Code$+=" A=123"            +eol$
      Code$+=" B=456"            +eol$
      Code$+=" C=999999"         +eol$
      Code$+=" Result=((A+B)/C)"   +eol$
      
#print code$
      dim me as P64_LEXED_CODE pointer
      me=PB64_LexCode(Code$)


      for lp=0 to Me.TokenCount
         
         Dim CurrentToken as P64_LEXER_TOKEN pointer
         CurrentToken = Me.TokenArray_P64_LEXER_TOKEN_PTR + (lp * sizeof(P64_LEXER_TOKEN))


         Select CurrentToken.Token
            
               case LEXTOKEN_WORD
                  ThisWord$ =Mid$(Code$,1+CurrentToken.StringOffset,CurrentToken.StringSize)
                  DrawWord("Token["+str$(lp)+"] = ",ThisWord$)
   
      
               case LEXTOKEN_ENDOFLINE
                  DrawWord("Token["+str$(lp)+"] = ","[EOL]",$ff0000)
                  
               default
                  // Assume Single ASC CHARACTER
                  if CurrentToken.StringSize =1
                     ThisWord$ = Chr$(CurrentToken.Token)
                     DrawWord("Token["+str$(lp)+"] = ",ThisWord$,$ffFF00)
                  endif
               
         EndSelect         
      next
EndFunction


Function DrawWord(Message$,Word$,Col=$00ff00)
   ypos   =getcursory()
   th      =gettextHeight("|")
   Text 0,ypos,Message$
   Xpos=GettextWidth(Message$)
   ink Col   
   Text xpos,ypos,Word$
   ink -1
   SetCursorY ypos+th
EndFunction


[/pbcode]


                 

Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on July 27, 2020, 09:01:48 AM

   PB Math64 - Lexical Scanner -> Syntax highlight


     Updated the lexer to pick up some missing tidbits.  Display bellow is the result, which gives a sort of syntax high lighted result, without white space. 


     Here's the sample to display the token buffer.

[pbcode]

      Eol$      =chr$(13)+chr$(10)
      Code$ =""
      Code$+=" Var A,B,C,D"      +eol$
      Code$+=" VaR Result"         +eol$
      Code$+=" result=cos(a)*1000"               +eol$
      Code$+=" s=-12345"               +eol$
      Code$+=" s= - 12345"               +eol$
      Code$+=" s= -12345"               +eol$
      
      Code$+="A"               +eol$
      Code$+="1"               +eol$
      Code$+=" A=1"               +eol$
      Code$+=" A=1."               +eol$
      Code$+=" A=11.22 "         +eol$
      Code$+=" A=33.e10"         +eol$
      Code$+=" A=1234567890.1234567890"            +eol$
      Code$+=" C=999999"         +eol$
      Code$+=" Result=((A+B)/C)"   +eol$
      
      #print code$



      TestSyntaxHighlighted(Code$)





function TestSyntaxHighlighted(Code$)
   
      dim me as P64_LEXED_CODE pointer
      me=PB64_LexCode(Code$)


      Th=GetTextHeight("|")
      Xpos =GetCursorX()
      Ypos =GetCursorY()
      PadX =4

      for lp=0 to Me.TokenCount
         
         Dim CurrentToken as P64_LEXER_TOKEN pointer
         CurrentToken = Me.TokenArray_P64_LEXER_TOKEN_PTR + (lp * sizeof(P64_LEXER_TOKEN))


         Select CurrentToken.Token
            
               case LEXTOKEN_WORD
                  ThisWord$ =Mid$(Code$,1+CurrentToken.StringOffset,CurrentToken.StringSize)
                  Ink $00FF00
                  Text Xpos,Ypos,ThisWord$
                  Xpos +=GetTextWidth(ThisWord$)+PadX

               case LEXTOKEN_LITERAL

                  ThisWord$=PB64_F64ToString(int(CurrentToken.LiteralValue))
                  Ink $ff00ff
                  Text Xpos,Ypos,ThisWord$
                  Xpos +=GetTextWidth(ThisWord$)+PadX

      
               case LEXTOKEN_ENDOFLINE
                  
                  ink $ff0000
                  Text Xpos,Ypos,"[EOL]"
                  Ypos=Ypos+TH+10
                  Xpos = 0
   
               //  Pick up keywords   ----------------------------------
               case 1100 to 2000
               // -------------------------------------------------
                  
                  
                  ThisWord$ =Mid$(Code$,1+CurrentToken.StringOffset,CurrentToken.StringSize)

                  ink -1   
                  Text Xpos,Ypos,ThisWord$
                  Xpos +=GetTextWidth(ThisWord$)+PadX

                  
               default
                  // Assume Single ASC CHARACTER
                  if CurrentToken.StringSize =1
                     ThisWord$ = Chr$(CurrentToken.Token)
//                     DrawWord("Token["+str$(lp)+"] = ",ThisWord$,$ffFF00)

                     ink $ffff00   
                     Text Xpos,Ypos,ThisWord$
                     Xpos +=GetTextWidth(ThisWord$)+PadX

                  endif
               
         EndSelect         
   next
   
   setcursory  Ypos   
EndFunction

[/pbcode]


    Next chore is write a parser that spits out the byte code for the solver.    It'll include a few common math operations  and some basic 64bit functions  (no point doing 32bit ones now is there)...






Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on July 28, 2020, 11:44:29 PM

PB Math64 - Expression Solving  - Getting out of control ;)



     So last night focus moved onto to building a mini compiler of sorts, which is something i'd not expected to be doing this week, but hey there you go..   We're basically at point now where i'm parsing the expressions and generating custom byte code to solve said operations.   The operations back end I wrote last week and has been sitting around gather dust ever since.   The idea of solver is that you can define chunks of basic like code, without having to resort to single operation functions or machine code like user code (as mentioned about),  meaning the code will look mostly like regular PlayBASIC code, making it easier to understand.  Using it, well.... that's another story.


     Let's go through what this is trying to be and what it's NOT going to do.. 



     1)  PB Math64  is built to solve 64BIT operations in FLOATING POINT.      (No integer support is planned)

     2)  PB Math64 will support basic math operations  ( ADD/ SUB/DIV/MULT)

     3)  PB Math64  will include various 64bit math functions (Cos/Sin/Sqrt/Exp etc).   
       
     4)  PB Math64 can not call internal PlayBASIC functions.. 
         


     and that's about it for today...


Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on August 03, 2020, 10:41:48 PM
   PB Math64 - Compiling

       Had a wishy washy week in terms of free time, but have finally got a mini compiler -> expression -> virtual machine fleshed out.   Taking the opportunity to try and fee different ideas during the process.  If you look at the screen shot in the previous post, you'll noticed that it see some negative literals and not others.    In PB a negative literal is actually handled as a negated positive literal.   Which means there's a little 'cleaning' up of the imported expression before we start solving it.  Which is OK, as that clean process does a few other things too (like recasting stuff), but if this occurs at token level, then we can't look back at the original source, so it's legal to write -1 as -      1    which always felt strange to me.    So this version of the parser is the subtraction symbol is next to literal (constant in other words), the lexer checks back to try and understand if this is a subtraction or a part of the number.  

       Another thing that i've been tinkering with, is using a structures for byte and code generation patterns.   In PB the opcode patterns are a list of offsets from the instruction.  Which is hard coded into the byte code creator and decoder.    What I've been wanting to try tho, is what type of code does C/C++ produce if we use structs for each instruction type.   On first test, this does produce different machine code for the virtual machine, but in some places it seems to pack the registers better, so it's not hitting memory as much per opcode.   For something that single use, that should mean that this would work better as external solver than ot ever could embedded into PB.
 
        The nice about using structures (TYPES in PB speak)  is that IF i change the field orders, then I don't have to change the decoder or creation routines.   In PB the byte patterns are dropped in a serial form.    


        Anyway, last night there's a lexer -> compiler and runtime set up..   Now it's just making sure it's working / then dropping in more operations.

Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on August 06, 2020, 12:25:46 PM

PlayBASIC LIVE -  Developing Math64 Library (2020-08-06  )

   Today we're take a quick tour at the new Math64 library for PlayBASIC.  The idea behind the library is to build an external solver for 64bit floating point math operations.  The solver will feature a PB styled reduced syntax but with only one data type, 64bit floats.  The library will compile and solve the expressions at runtime.    Those are where we're going tho, the current version barely parses and compiles a simple expression, but we're getting there.




Video:


   





Credits:



      Video By:
   Kevin Picone
   http://PlayBASIC.com 
   https://Underwaredesign.com

   Music:
  Spirit of Fire by  Jesse Gallagher





PlayBASIC LIVE PLAYLIST
https://www.youtube.com/playlist?list=PL_dvm0gvzzIVGlAhx34N6z2ce0ffMMOZ8

PlayBASIC BLOG PLAYLIST
https://www.youtube.com/playlist?list=PL_dvm0gvzzIU0Hnr6veV5UvwkSapHCo1J

PlayBASIC on FACEBOOK
http://www.facebook.com/pages/PlayBasic/127905400584274   (Facebook Page)

PlayBASIC on TWITTER
https://twitter.com/PlayBasic



#PlayBASIC #coding #basic #programming #sourcecode #64bit #floatingpoint
Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on August 08, 2020, 11:06:31 PM

  PlayBASIC Math64  - Expression Evaluation - Brackets with Mults/Divisions  (2020-08-06)

      So expanded the code to handle firstly handle multiplies and divisions and then dropped in support for brackets.   It should be noted that there's unary operators in this, so you can't go  A= -B   rather you'd have to write it as  A=B * -1 and of course as mentioned before there's little to no error detection.   Will drop that in once I know what the limits are.   


      Another change is this version is parsing the entire program.   So the code bellow is lexed and fully compiled as seen in the attched picture.  I've added some lines to show what the input code is and what it produces.  You'll notice some lines produce no code (as as VAR declartions) and those that do have some pre-evaluation going on, but only a TINY amount of it.   So pretty much whatever you write ends up in the output code.



Var A,B,C,D
VaR Result,s
Result=1234.5678 * 122121.54
Result=a+100+(b+c-d)*(10/2) - (A-A)
s=-12345
s=0 - -12345
s= -12345



 


      attached is a display of syntax highlighted input code compared to the compiled byte code..


Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on August 12, 2020, 11:01:35 PM
  PlayBASIC Math64  - Compiling & Executing 64bit Expressions (2020-08-13)


     Wow,  it's been almost a month, but today i can announce that the library has finally sprung to life.  In that it can parse/compile and execution the expressions on it's own custom runtime.   Almost I've added support for  various function, some limited literal pre-solving of operations and most math functions too.    So code like A= cos(45)  , sees the compiler compute Cos(45) and export only a move into the byte code.  
   

     Functions it currently supports

           ABS()
           CEIL()
           FLOOR()
           COS()
           SIN()
           ACOS()
           ASIN()



    The trig functions are direct wrappers so they expect RADIANS not angles.    I'll add some functions to convert Radian to Degree and vice versa later.    What I might do is have them work with ANGLES by default, then add versions that expect Radians.   Prolly with a R attached or something.   Was going to do this to PB anyway, but just haven't as yet.  


     For usage,  you pass the Compile function a block of code (in string form) to be compiled into a mini program.  The function returns a program pointer, that is then passed to EXECUTE PRG function that will run this logic.    That's all good and all, but there's not easy way to read and write the variables from an executed program.   So that's something we'll have to iron out but trying to make use of the library structure.     

     So the usage structure looks like


     Prg=PB64_Compile(Code$)

     if PRG

            PB64_Execute(PRG)
     endif



        If you have math functions you would like to see implemented in the library, then do so BELLOW

Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on August 17, 2020, 11:53:54 PM
   PlayBASIC Math64  - Public Test  (2020-08-18)

     Ok, guys here the state of the library today.  It supports basic math operators . Brackets and mostly simple trig functions..   I'm editing a video about it today, so that will cover this a little more.  But for now you can play !


      Note: the protect is being built using PlayBASIC V1.65,  but you should be able to get it running from V1.64P  editions.  (untested)



   Video:

   




  Download
 
     Attached
Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on August 19, 2020, 10:44:03 AM
Just adding support for comparison operators and doing a little bench marking.   So running the following code takes approximately 380 milliseconds to run it 1,000,000 times.  So that gives us around 100 million mixed operations per second.  

--[ TEST CODE ] -----------------------------------------------

Var A,B,C,D
VaR Result,s
Result = 100<>200
 Result = A<A + A<=B + A<>B
 Result = A>A + A>=B + A><B
D =0 + B
Result=abs(1234.567)
A=floor(cos(90))
B=floor(sin(90))
A=floor(acos(90))
B=floor(asin(90))
A=floor(cosradius(90,100))
B=floor(sinradius(90,100))
A=floor(cosradius(a,a))
B=floor(sinradius(a,a))
A=floor(newcosvalue(100,90,100))
B=floor(newsinvalue(100,90,100))
Result=tan(90)
Result=atan(90)
Result=sqrt(1234567)
Result=sqrt(123456)
Result=a+100+(b+c-d)*(10/2) - (A-A-A)
s=(10/2)






  Today's Edit:



  It seems we're been a bit conservative with our math libraries runtime performance as today's tweaked version runs the same test code (including two more functions) consistently at around 210 milliseconds per 1,000,000 calls.

  There's about 40 instructions being processed per call, so our per second performance is pushing 200 million opcodes per second (40 * 5) =200 * 1 Million

  I doubt it'll stay at that level, but it's nice to see at least.



Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on August 23, 2020, 10:20:11 AM
  PlayBASIC Math64  V002 - Public Test  (2020-08-24)

       Here's the second release of the Math64 library.  In this one we've a few new addition such as support for comparison and boolean logic operations (AND , OR , XOR)  as wellas some helper functions so you get data from the executed script.   Look at the test for what's available.  


      Performance wise, well it's pretty quick.. Check out the performance estimates bellow..  200 odd millions instructions per second  :)




---[ EXECUTION  ]---------------------------------

  251 Ticks TO Execute [1000000] Times  
  59 Instructions in byte code
 Approx 235.0598 MILLION 64bit Opcodes Per Second


  80 Ticks - Read / Write Variable Result [1000000] Times  



---------[ TEST CODE ] -------------------------------------------------
Var A,B,C,D
VaR Result,s,count
VaR CopyOfResult
Result = 0.0 and 0.0
Result = 1.0 and 0.0
Result = 0.0 and 1.0
Result = 1.0 and 1.0
Result = 0.0 or 0.0
Result = 1.0 or 0.0
Result = 0.0 or 1.0
Result = 1.0 or 1.0
Result = 0.0 xor 0.0
Result = 1.0 xor 0.0
Result = 0.0 xor 1.0
Result = 1.0 xor 1.0
Result = A=A and b=b
Count=Count+1
Result = 100<>200
Result = 100=A
Result = 100<>A
 Result = A=A
 Result = A<A + A<=B + A<>B
 Result = A>A + A>=B + A><B
D =DEgreeToRAdian(90)
D =RAdianToDegree(90)
D =0 + B
Result=abs(1234.567)
A=floor(cos(90))
B=floor(sin(90))
A=floor(acos(90))
B=floor(asin(90))
A=floor(cosradius(90,100))
B=floor(sinradius(90,100))
A=floor(cosradius(a,a))
B=floor(sinradius(a,a))
A=floor(newcosvalue(100,90,100))
B=floor(newsinvalue(100,90,100))
Result=tan(90)
Result=atan(90)
Result=sqrt(1234567)
Result=sqrt(123456)
Result=a+100+(b+c-d)*(10/2) - (A-A-A)
s=(10/2)




      Note: the protect is being built using PlayBASIC V1.65,  but you should be able to get it running from V1.64P  editions.  (untested)





  Video:

 




  Download
 
     Attached
Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on October 04, 2020, 09:52:39 PM
    PlayBASIC Math64  - Import /Exporting Structures

   It's been a few weeks since the last build of PBMath64 was issued and there's a couple of things that need to be sorted before calling it a library.   One issue is how to move data from the 32Bit side into the library and back again in the most efficient way possible.  While you can read/write variables directly which is fine for small fragments, but not great if there's a cluster of variables that need to be imported constantly, as it'd chew through most of the performance gains.  So i was thinking about setting up some way the user could import from their structure into the script, run the script and have it dump the results back into the structures pointer if needed, as sometimes you wouldn't.


   How would this look ?  I dunno, but I was the simplest approach possible that can be wrapped into a single instruction on the math64 runtime side.  One idea might be to set a starting pointer of where it'll copy the fields form as if it was a data statements.  

   So we'd set the source structure pointer (pointer to the type with the FLOAT fields in it) then in the script have some sort of READ or COPY command in the script.


   If we use the type particle example,  our PB loop might loop like this.
[pbcode]

    Type tParticle
            Status
            x,y
            vx,vy
            clippingRectX1
            clippingRectY1
            clippingRectX1
            clippingRectY1
    endtype

    For lp=0 to NumberOfParticles

         if Particle(lp)
             Me =Particle(lp).tParticle

          // Calll our script and pass it the address of this structure to copy out of
             CallMathScript PointerMath64Program , int(me)

         endif
    next
[/pbcode]


    Then the import script could be




     ImportFromStructure  1 , Status, X,Y,VX,VY,ClipX1,ClipY1,ClipX2,ClipY2

     X=X+VX
     Y=Y+VY
     VY =VY +0.25

     Status = (X>=ClipX1) and (X<ClipX2) and Y>=0 and Y<ClipY2




 
Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on October 24, 2020, 09:56:10 AM

     PlayBASIC Math64  - IF / ENDIF block statements


      Trying to pick this up after about a month away from the keyboard is an interesting challenge and if tonight is anything to go by,  it's not going well :)   - Thus far I've added the IF / ENDIF parsing and code generation but when I test it it hangs..    Been picking through it but can't quite put my finger on the issue at this time. 

      We'll try again when i'm not so tired i guess. 
Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on October 27, 2020, 10:27:07 AM
  PlayBASIC Math64  - IF / ENDIF block statements #2

     Fired up the project the other night and discovered the initial problem that was preventing the IF / ENDIF parsing and code generation from working, which turned out to be a missing break.   Ya get that..   Then manged to ran into a bit of odd logic problem, but that's been located and easily fixed now too.  

     So all this means is there's now ability to make decisions within the script.  ELSE is missing for the time being, but i'll have to drop that in next time.  



---[ Source Code ] ---------------------------------------------------
Var A,B,C,D,E
VaR Result,s,count
VaR CopyOfResult
A=50+50
B = (A=100.0)
if C<>0
 C=123.456
endif
if D=0 and B=1
    D=123456.678
endif
if D>1000
   if B=1
     E=5544.11
   endif
endif




Becomes the folowing byte code..    There's a couple of things could be tweaked, but i'll get over it.





---[ BYTE CODE VIEW ]---------------------------------

#0>> Move Value [0] = [$00000000$40590000]Val=100.0
#16>> CMP [1] = [0] = [9]
#32>> CMP [10] = [2] <> [11]
#48>>  CMP_BOZ [10] = 0  -> BRANCH 76
#60>> Move Value [2] = [$1A9FBE77$405EDD2F]Val=123.45
#76>> CMP [10] = [3] = [11]
#92>> CMP [13] = [1] = [12]
#108>> AND [14] = [10] & [13]
#124>>  CMP_BOZ [14] = 0  -> BRANCH 152
#136>> Move Value [3] = [$D916872B$40FE240A]Val=123456.67
#152>> CMP [10] = [3] > [15]
#168>>  CMP_BOZ [10] = 0  -> BRANCH 224
#180>> CMP [10] = [1] = [12]
#196>>  CMP_BOZ [10] = 0  -> BRANCH 224
#208>> Move Value [4] = [$28F5C28F$40B5A81C]Val=5544.109999999999
#224>> END





Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on October 29, 2020, 10:23:49 PM

   PlayBASIC Math64  - IF / ELSE / ENDIF block statements

        So dropped in parsing and instruction support so that the scripts can be include ELSE path ways in the output code.   I guess we should add and ElseIF statement too which is basically slightly tweaked IF parser.  The main thing missing is ERRORs from the library,  which I think i'll just embedd a test hash rather than a numeric error code.  So the library will that there's an parsing error, but return a string.   I dunno..





---[ Source Code ] ---------------------------------------------------
Var A,B,C,D,E,F
VaR Result,s,count
VaR CopyOfResult
if D<1000
     E=1
   else
     E=2
endif
if D>1000
     F=1
   else
     F=2
endif

Error Status:0  $00000000




  Byte code




---[ BYTE CODE VIEW ]---------------------------------

#0>> CMP [11] = [3] < [10]
#16>>  CMP_BOZ [11] = 0  -> BRANCH 52
#28>> Move Value [4] = [$00000000$3FF00000]Val=1.0
#44>>  JMP REAL  -> BRANCH 68
#52>> Move Value [4] = [$00000000$40000000]Val=2.0
#68>> CMP [11] = [3] > [10]
#84>>  CMP_BOZ [11] = 0  -> BRANCH 120
#96>> Move Value [5] = [$00000000$3FF00000]Val=1.0
#112>>  JMP REAL  -> BRANCH 136
#120>> Move Value [5] = [$00000000$40000000]Val=2.0
#136>> END


Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on October 31, 2020, 11:11:26 AM

PlayBASIC Live -  PB Math64  - Status Update #3 - Adding IF ELSE ENDIF LOGIC  (2020-10-31)


   Today we take a look at the latest changes to the Math64 library for PlayBASIC.   Since  last update the main changes would have to the be the addition of the IF/ELSE/ENDIF control statements.  Allowing your script to make decisions and act upon them. 

Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on October 31, 2020, 10:33:06 PM
  PlayBASIC Math64  V003 - Public Test  (2020-11-01)

       Here's the third release of the Math64 library.  In this one we've added support for the IF / ELSE / ENDIF decisions.

       Here's the sample code that is build within the project.   You can import your own of course, but that's up to you.



Var A,B,C,D,E,F
VaR Result,s,count
VaR CopyOfResult
if D<1000
    E=1
  else
    E=2
endif
if D>1000
    F=1
  else
    F=2
endif



      Note: the project is being built using PlayBASIC V1.65,  but you should be able to get it running from V1.64P  editions or older.  (untested)



  Video:

 




  Download
 
     Attached
Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on November 20, 2020, 10:46:33 PM

  PlayBASIC Math64  - ERROR MESSAGES /  COMMENTS & COPYTO / COPYFROM Variables


        I've had the morning off of sorts and have used that time to improve the library one more step, with the addition of come group copying functions that allow us to copy variables from the PLAYBASIC side to the math64 side.  These take the form of some CopyTOVariable and CopyFromVariable functions.  There's a few editions of them but basically you tag the variable in the script you watch to copy to or from and the location in memory where it should read or write.        So what you'll do is write a structure on the PlayBASIC side and then and then mirror that structure on the script side. 


         Example:



  //   PlayBASIC code
      type tParticle
          Status#
          X#,Y#
          Xspeed#,ySpeed#
      endtype



   // Script would have these declared as variables

        var  Status,x,y,xspeed,yspeed




     So setup the script we use the CopyToVariables function to copy the 5 fields in the script, then once the script is over,  we use the CopyFromVariables function to get them back.   This gives us less interactions and less hands on conversion, but does place the onus on the user (YOU) to make sure both sides variables are in the correct order and data type. 

Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on November 26, 2020, 06:08:58 AM
 PlayBASIC Math64  V004 - Public Test  (2020-11-26)


      Here's revision 4 of the library, this one includes support for comments , Basic Error Messages and group variable copying.





  PlayBASIC LIVE -  Math64   STATUS -  Adding ERRORS & COPY FUNCTIONS and VECTORS ? (2020-11-26)

 



     Also See->  [plink]Vector Stacks (https://www.underwaredesign.com/forums/index.php?topic=3838.0)[/plink]





  Download
 
     Attached.
Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on November 30, 2020, 09:18:30 PM
 PlayBASIC Math64  - Adding support for Vector2 / Vector3 and Vector4



     So while on the way to somewhere else this apparently happened..   The current build only parses the declaration and classifies them in the variable stack, but we can't access the fields nor does it have any code generation for the operations between vectors.  But  

     Bellow is the current status of the Vector example, hardly all that interesting.  



//  -------------------------------------------------
//  -----------[ VEcTOR EXAMPLE ]--------------------
//  -------------------------------------------------


var A,B,C,D,E

vector2  Pos, Speed




      One of the barriers for entry to adding more data types, is the whole thing was based around there only being one data type, 64bit floats,  thus this has to fit with the defined limitations of what i already have.  So vectors are also 64bit.

      You can think of your program as defining a TYPE in PlayBASIC actually, so the fields all stack up on top of each other,  there's one limitation is fields need to be 64bits wide, all of them.  So even if I added a BYTE / WORD / FLOAT32 type they'd take 64bits in this design.  So we'll just suck it up for the time being, but I don't foresee this being a show stopper.  


      This also means that variables are single instance,  So you can't have a variable called POS and a Vector called POS, it'll give you a syntax error for the time being but ideally it'll pop a redefined error.  

     The trick is going to be how we access the fields within a vector.  In PlayBASIC when a type is declared, it creates a list of the potential expanded field names,  but we might just be able to to detect these during expression evaluation and output them as normal variables.   Both have up and down sides,  I think i'll try the latter first.   If it causes some dumb issue down the road, then i'll have to suck it up and put on my big boy pants and do it correctly, whatever that means.

        So now the questions,  what FUNCTIONS would be handy when dealing with VECTORS ??
 


Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on December 02, 2020, 07:58:12 AM
A little over and hour and the Math64 Parser thinks we have Vectors2/3 & 4...  well, it can parse and generate the simple code to read the fields bellow.


var A,B,C,D,E

vector2  Pos, Speed

A = pos.x + pos.y


All that for a this




---[ BYTE CODE VIEW ]---------------------------------

#0>> Add [0] = [5] + [6]
#16>> END

---[ VARIABLE DEFINES TABLE ]---------------------------------

#0=A   Type:1 -  Stack:0 -  Hash:$01000041 -  StringOffset:16-1 -
#1=B   Type:1 -  Stack:1 -  Hash:$01000042 -  StringOffset:18-1 -
#2=C   Type:1 -  Stack:2 -  Hash:$01000043 -  StringOffset:20-1 -
#3=D   Type:1 -  Stack:3 -  Hash:$01000044 -  StringOffset:22-1 -
#4=E   Type:1 -  Stack:4 -  Hash:$01000045 -  StringOffset:24-1 -
#5=Pos   Type:1 -  Stack:5 -  Hash:$030000F2 -  StringOffset:26-3 -
#6=Speed   Type:1 -  Stack:7 -  Hash:$05000171 -  StringOffset:30-5 -


Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on December 05, 2020, 08:21:36 AM
   Couple of sessions later and it actually has working Vector2 support, managed to run into one of those structure unbalanced issues today, so lost most of my free time chasing my own tail, only to then realize that the C compiler was padding a structure.  This causes problems because PlayBASIC doesn't do this,  so even though the fields are the same, the C back end thinks variable table structure was 40 bytes wide, when only 36 bytes are in use..   what joy !  Meaning it'd crash.


   Bellow we have our junk test, the expression side is being evaluated but the result vector isn't being written out as yet..   Tomorrow

 




//  -------------------------------------------------
//  -----------[ VEcTOR EXAMPLE ]--------------------
//  -------------------------------------------------


var A,B,C,D,E

vector2  Pos, Speed

//A = pos.x + pos.y

     // This expression doesn't make any sense, but the parser currently allows it
A = pos + Speed







   and here's the output.




---[ VARIABLE DEFINES TABLE ]---------------------------------

Variables:8
#0=A   Class:1 - Class:2 -  Stack:0 -  Hash:$01000041 -  StringOffset:16-1 -
#1=B   Class:1 - Class:2 -  Stack:1 -  Hash:$01000042 -  StringOffset:18-1 -
#2=C   Class:1 - Class:2 -  Stack:2 -  Hash:$01000043 -  StringOffset:20-1 -
#3=D   Class:1 - Class:2 -  Stack:3 -  Hash:$01000044 -  StringOffset:22-1 -
#4=E   Class:1 - Class:2 -  Stack:4 -  Hash:$01000045 -  StringOffset:24-1 -
#5=Pos   Class:1 - Class:100 -  Stack:5 -  Hash:$030000F2 -  StringOffset:26-3 -
#6=Speed   Class:1 - Class:100 -  Stack:7 -  Hash:$05000171 -  StringOffset:30-5 -
#7=~TEMP0000   Class:1 - Class:100 -  Stack:9 -  Hash:$09000274 -  StringOffset:36-9 -



---[ BYTE CODE VIEW ]---------------------------------

#0>> Add [9].Vector2 = [5].Vector2 + [7].Vector2
#16>> END

 


    Notice the  Add [9].Vector2 = [5].Vector2 + [7].Vector2  instruction with does the addition. 
Title: Re: 64 Bit Floating Point Math Library for PlayBASIC ?? Interested ?
Post by: kevin on December 06, 2020, 10:33:22 PM
PlayBASIC LIVE:  PB Math64  -  Adding VECTORS  (2020-12-07)


  Here's the latest addition to Math64 library VECTORS








   Download
 
      Attached.
Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on December 09, 2020, 07:17:42 AM


  PlayBASIC LIVE:  PB Math64  -  Adding VECTORS  (2020-12-09)


     Continuing on from the post above, I ended up biting the bullet and implementing the VECTOR support in the parser allowing for the fields to be not only read, but written to..   The initial version was a hack and this creates the fields as individual variables in the stack, so accessing a field within a VECTOR is the same as a VARIABLE.


     Next problem is going to be how to handle Functions for Vectors.  Initially I think we'll end up with copies of various function for the particular data type,  as internally it has no way of understanding what fields are what.   Remember this was only ever meant to use a single data type..  So were breaking out our rules here.     I actually think that have different functions names for function isn't the end of the world, but if I can implementing sometype of simple overloading I'll see about shoving it in later on.       





--[ Source Code ] ---------------------------------------------------

//  -------------------------------------------------
//  -----------[ VEcTOR EXAMPLE ]--------------------
//  -------------------------------------------------


var A,B,C,D,E

vector2  Pos, Speed

speed.x = 100
speed.y = 220

speed.x = 1111

a = Speed.X

pos = pos + Speed
pos = pos - Speed
pos = pos * Speed
pos = pos / Speed






---[ End Of Source Code ] ---------------------------------------------------
Error  Status:0  $00000000
Error Message:


---[ VARIABLE DEFINES TABLE ]---------------------------------

Variables:14
#0=A   Class:1 - Class:2 -  Stack:0 -  Hash:$01000041 -  StringOffset:16-1 -
#1=B   Class:1 - Class:2 -  Stack:1 -  Hash:$01000042 -  StringOffset:18-1 -
#2=C   Class:1 - Class:2 -  Stack:2 -  Hash:$01000043 -  StringOffset:20-1 -
#3=D   Class:1 - Class:2 -  Stack:3 -  Hash:$01000044 -  StringOffset:22-1 -
#4=E   Class:1 - Class:2 -  Stack:4 -  Hash:$01000045 -  StringOffset:24-1 -
#5=Pos   Class:1 - Class:100 -  Stack:5 -  Hash:$030000F2 -  StringOffset:26-3 -
#6=Pos.X   Class:1 - Class:2 -  Stack:5 -  Hash:$05000178 -  StringOffset:30-5 -
#7=Pos.Y   Class:1 - Class:2 -  Stack:6 -  Hash:$05000179 -  StringOffset:36-5 -
#8=Speed   Class:1 - Class:100 -  Stack:7 -  Hash:$05000171 -  StringOffset:42-5 -
#9=Speed.X   Class:1 - Class:2 -  Stack:7 -  Hash:$070001F7 -  StringOffset:48-7 -
#10=Speed.Y   Class:1 - Class:2 -  Stack:8 -  Hash:$070001F8 -  StringOffset:56-7 -
#11=~TEMP0000   Class:1 - Class:100 -  Stack:9 -  Hash:$09000274 -  StringOffset:64-9 -
#12=~TEMP0000.X   Class:1 - Class:2 -  Stack:9 -  Hash:$0B0002FA -  StringOffset:74-11 -
#13=~TEMP0000.Y   Class:1 - Class:2 -  Stack:10 -  Hash:$0B0002FB -  StringOffset:86-11 -



---[ BYTE CODE VIEW ]---------------------------------

#0>> Move Value [7] = [$00000000$40590000]Val=100.0
#16>> Move Value [8] = [$00000000$406B8000]Val=220.0
#32>> Move Value [7] = [$00000000$40915C00]Val=1111.0
#48>> Move [0] = [7]
#60>> Add [9].Vector2 = [5].Vector2 + [7].Vector2
#76>> Copy [5] = [9]+ [2]
#92>> Sub [9].Vector2 = [5].Vector2 + [7].Vector2
#108>> Copy [5] = [9]+ [2]
#124>> Mult [9].Vector2 = [5].Vector2 + [7].Vector2
#140>> Copy [5] = [9]+ [2]
#156>> Div [9].Vector2 = [5].Vector2 + [7].Vector2
#172>> Copy [5] = [9]+ [2]
#188>> END


Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on December 12, 2020, 09:38:41 AM
  PlayBASIC LIVE:  PB Math64  -  Adding Vector Functions (2020-12-12)


     So... I've been working on this today and have finally got it to a point where a function can be defined that returns a VECTOR2/3 or 4, then have function be parsed during expression evaluation and byte code generated and executed at runtime..    yay...  which is the life cycle of a function.   At this point it only supports one function GetNormalVector2D which is meant to accept a vector2 parameter and return the normal vector2d from it.   But it actually doesn't work due to the function parameter matching not understanding what a vector parameter is,  but you can pass a variable in it's place and it'll treat that variable and the one directly following it in the stack as a vector.   After all a vector2 is nothing more than pair of X/Y variables conceptually fussed together.  


    Here's a dump of the console output tonight..    The byte code still has some redundant operations regarding Vectors and at this point only Vector2 is mostly hooked up.  The other two should be a lot easier and then we'll see what you can get it to do.   




--[ Source Code ] ---------------------------------------------------

//  -------------------------------------------------
//  -----------[ VEcTOR EXAMPLE ]--------------------
//  -------------------------------------------------


var A,B,C,D,E

vector2  Pos, Speed

A = 100
B=200
C= A * B
speed.x = 1
speed.y = 2

a = Speed.X

pos = pos + Speed
pos = pos - Speed
pos = pos * Speed
pos = pos / Speed


a = cos(b)

a = 100
b=100
POS = GetVectorNormal2D(A)




---[ End Of Source Code ] ---------------------------------------------------
Error  Status:0  $00000000
Error Message:


---[ VARIABLE DEFINES TABLE ]---------------------------------

Variables:15
#0=A   Class:1 - Class:2 -  Stack:0 -  Hash:$01000041 -  StringOffset:16-1 -
#1=B   Class:1 - Class:2 -  Stack:1 -  Hash:$01000042 -  StringOffset:18-1 -
#2=C   Class:1 - Class:2 -  Stack:2 -  Hash:$01000043 -  StringOffset:20-1 -
#3=D   Class:1 - Class:2 -  Stack:3 -  Hash:$01000044 -  StringOffset:22-1 -
#4=E   Class:1 - Class:2 -  Stack:4 -  Hash:$01000045 -  StringOffset:24-1 -
#5=Pos   Class:1 - Class:100 -  Stack:5 -  Hash:$030000F2 -  StringOffset:26-3 -
#6=Pos.X   Class:1 - Class:2 -  Stack:5 -  Hash:$05000178 -  StringOffset:30-5 -
#7=Pos.Y   Class:1 - Class:2 -  Stack:6 -  Hash:$05000179 -  StringOffset:36-5 -
#8=Speed   Class:1 - Class:100 -  Stack:7 -  Hash:$05000171 -  StringOffset:42-5 -
#9=Speed.X   Class:1 - Class:2 -  Stack:7 -  Hash:$070001F7 -  StringOffset:48-7 -
#10=Speed.Y   Class:1 - Class:2 -  Stack:8 -  Hash:$070001F8 -  StringOffset:56-7 -
#11=~TEMP0000   Class:1 - Class:2 -  Stack:9 -  Hash:$09000274 -  StringOffset:64-9 -
#12=~VEC20000   Class:1 - Class:100 -  Stack:10 -  Hash:$0900024E -  StringOffset:74-9 -
#13=~VEC20000.X   Class:1 - Class:2 -  Stack:10 -  Hash:$0B0002D4 -  StringOffset:84-11 -
#14=~VEC20000.Y   Class:1 - Class:2 -  Stack:11 -  Hash:$0B0002D5 -  StringOffset:96-11 -



---[ BYTE CODE VIEW ]---------------------------------

#0>> Move Value [0] = [$00000000$40590000]Val=100.0
#16>> Move Value [1] = [$00000000$40690000]Val=200.0
#32>> MULT [2] = [0] * [1]
#48>> Move Value [7] = [$00000000$3FF00000]Val=1.0
#64>> Move Value [8] = [$00000000$40000000]Val=2.0
#80>> Move [0] = [7]
#92>> Add [10].Vector2 = [5].Vector2 + [7].Vector2
#108>> Copy [5] = [10]+ [2]
#124>> Sub [10].Vector2 = [5].Vector2 + [7].Vector2
#140>> Copy [5] = [10]+ [2]
#156>> Mult [10].Vector2 = [5].Vector2 + [7].Vector2
#172>> Copy [5] = [10]+ [2]
#188>> Div [10].Vector2 = [5].Vector2 + [7].Vector2
#204>> Copy [5] = [10]+ [2]
#220>> [0] = COS( [1])
#236>> Move Value [0] = [$00000000$40590000]Val=100.0
#252>> Move Value [1] = [$00000000$40590000]Val=100.0
#268>> [10] = GetNormal2D( [0])
#284>> Copy [5] = [10]+ [2]
#300>> END


---[ LAST EXPRESSION TABLE ]---------------------------------

#0  Token=1011 -  SrcIndex=105 -  Stack=10 -  LiteralData=$00000000$00000000


---[ EXECUTION  ]---------------------------------

   149 Ticks TO Execute [1000000] Times 
   20 Instructions in byte code
  Approx 134.2282 MILLION 64bit Opcodes Per Second


   91 Ticks - Read / Write Variable Result [1000000] Times 


0
---[ VARIABLES POINTER ]---------------------------------

[Result] Variable Ptr=0
[Result] Variable Flt=0.0


---[ VARIABLES ]---------------------------------

A=100.0
B=100.0
C=20000.0
D=0.0
E=0.0
Pos=0.7071067811865474
Pos.X=0.7071067811865474
Pos.Y=0.7071067811865474
Speed=1.0
Speed.X=1.0
Speed.Y=2.0
~TEMP0000=0.0
~VEC20000=0.7071067811865474
~VEC20000.X=0.7071067811865474
~VEC20000.Y=0.7071067811865474




Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on December 13, 2020, 11:03:08 PM
PlayBASIC LIVE:  PB Math64  -  Adding VECTORS  (2020-12-14)


  Hey presto here's today's build of math64

  This one includes some very simple function support for VECTOR2 ..   Vector3 & 4 will parse, but there's nothing on the back end as yet to do such things..  

 
    Sample code


//  -------------------------------------------------
//  -----------[ VEcTOR EXAMPLE ]--------------------
//  -------------------------------------------------


var A,B,C,D,E, Size

vector2  Pos, Speed, SpeedNormal


A = 100
B=200
C= A * B
speed.x = 1
speed.y = 2

a = Speed.X

pos = pos + Speed
pos = pos - Speed
pos = pos * Speed
pos = pos / Speed


a = cos(b)


//  Compute normal from Speed vector
SpeedNormal = GetNormal2D(Speed)

//  get the length / size of this vector
Size = GetLength2D(Speed)


a = GetDotProduct2D(Pos,Speed)

// this is if a bit iffy in 2D
a = GetCrossProduct2D(Pos,Speed)

// ------------------------------------------------------
//  copy the normal vector to variables NX + NY
// ---------------------------------------------------------

// delcare a pair of variables
var nx,ny

// Set the speed vector
Speed.X = 200
Speed.Y = 100

// compute normal from Speed and write to NX and NY
Nx = getNormal2D(Speed)

// Compute normal and write result to the SpeedNormal vector
SpeedNormal = getNormal2D(Speed)





      Functions will accept almost anything which is a by product having no strict parameter matching.    Meaning you can pass a Variable in place of a vector, if you do this, it'll  treat that variable as the parent pointer and thus read/ write the fields from this address.    In the example above I'm testing this when retrieving the normal from the speed vector and writing it variable NX.    The function will copy over the NX variable as well as the NY variable declared after it.  




  Download
 
     Attached.
Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on December 18, 2020, 08:27:37 AM
 PlayBASIC LIVE:  PB Math64  -  Adding VECTOR3  (2020-12-19)


    Just touching base really, as we've had some more progress with the library,  this time seeing the VECTOR3 support come to life..  

     Check out the debug dump bellow...  




---[ Source Code ] ---------------------------------------------------

//  -------------------------------------------------
//  -----------[ VEcTOR EXAMPLE ]--------------------
//  -------------------------------------------------


var A,B,C,D,E, Size

vector2  Pos, Speed, SpeedNormal


A = 100
B=200
C= A * B
speed.x = 1
speed.y = 2

a = Speed.X

pos = pos + Speed
pos = pos - Speed
pos = pos * Speed
pos = pos / Speed


a = cos(b)


//  Compute normal from Speed vector
SpeedNormal = GetNormal2D(Speed)

//  get the length / size of this vector
Size = GetLength2D(Speed)


a = GetDotProduct2D(Pos,Speed)

// this is if a bit iffy in 2D
a = GetCrossProduct2D(Pos,Speed)

// ------------------------------------------------------
//  copy the normal vector to variables NX + NY
// ---------------------------------------------------------

// delcare a pair of variables
var nx,ny

// Set the speed vector
Speed.X = 200
Speed.Y = 100

// compute normal from Speed and write to NX and NY
Nx = getNormal2D(Speed)

// Compute normal and write result to the SpeedNormal vector
SpeedNormal = getNormal2D(Speed)



// ------------------------------------------------------
//  TEST VECTOR3 OPERATIONS
// ---------------------------------------------------------

var DotProduct3
vector3 pos3, Speed3, Cross3, Normal3

pos3.x = 100
pos3.y = 200
pos3.z = 300

speed3.x = 1
speed3.y = 2
speed3.z = 3

pos3 = pos3 + Speed3
pos3 = pos3 * Speed3
pos3 = pos3 / Speed3
pos3 = pos3 - Speed3

//  
Size = GetLength3D(pos3)
dotProduct3 = GetDotProduct3d(pos3,speed3)
Cross3 = GetCrossProduct3d(pos3,speed3)
Normal3 = getNormal3D(pos3)



---[ End Of Source Code ] ---------------------------------------------------
Error  Status:0  $00000000
Error Message:


---[ VARIABLE DEFINES TABLE ]---------------------------------

Variables:42
#0=A   Class:1 - Class:2 -  Stack:0 -  Hash:$01000041 -  StringOffset:16-1 -
#1=B   Class:1 - Class:2 -  Stack:1 -  Hash:$01000042 -  StringOffset:18-1 -
#2=C   Class:1 - Class:2 -  Stack:2 -  Hash:$01000043 -  StringOffset:20-1 -
#3=D   Class:1 - Class:2 -  Stack:3 -  Hash:$01000044 -  StringOffset:22-1 -
#4=E   Class:1 - Class:2 -  Stack:4 -  Hash:$01000045 -  StringOffset:24-1 -
#5=Size   Class:1 - Class:2 -  Stack:5 -  Hash:$0400013B -  StringOffset:26-4 -
#6=Pos   Class:1 - Class:100 -  Stack:6 -  Hash:$030000F2 -  StringOffset:31-3 -
#7=Pos.X   Class:1 - Class:2 -  Stack:6 -  Hash:$05000178 -  StringOffset:35-5 -
#8=Pos.Y   Class:1 - Class:2 -  Stack:7 -  Hash:$05000179 -  StringOffset:41-5 -
#9=Speed   Class:1 - Class:100 -  Stack:8 -  Hash:$05000171 -  StringOffset:47-5 -
#10=Speed.X   Class:1 - Class:2 -  Stack:8 -  Hash:$070001F7 -  StringOffset:53-7 -
#11=Speed.Y   Class:1 - Class:2 -  Stack:9 -  Hash:$070001F8 -  StringOffset:61-7 -
#12=SpeedNormal   Class:1 - Class:100 -  Stack:10 -  Hash:$0B00033A -  StringOffset:69-11 -
#13=SpeedNormal.X   Class:1 - Class:2 -  Stack:10 -  Hash:$0D0003C0 -  StringOffset:81-13 -
#14=SpeedNormal.Y   Class:1 - Class:2 -  Stack:11 -  Hash:$0D0003C1 -  StringOffset:95-13 -
#15=~TEMP0000   Class:1 - Class:2 -  Stack:12 -  Hash:$09000274 -  StringOffset:109-9 -
#16=~VEC20000   Class:1 - Class:100 -  Stack:13 -  Hash:$0900024E -  StringOffset:119-9 -
#17=~VEC20000.X   Class:1 - Class:2 -  Stack:13 -  Hash:$0B0002D4 -  StringOffset:129-11 -
#18=~VEC20000.Y   Class:1 - Class:2 -  Stack:14 -  Hash:$0B0002D5 -  StringOffset:141-11 -
#19=nx   Class:1 - Class:2 -  Stack:15 -  Hash:$020000A6 -  StringOffset:153-2 -
#20=ny   Class:1 - Class:2 -  Stack:16 -  Hash:$020000A7 -  StringOffset:156-2 -
#21=DotProduct3   Class:1 - Class:2 -  Stack:17 -  Hash:$0B00033B -  StringOffset:159-11 -
#22=pos3   Class:1 - Class:101 -  Stack:18 -  Hash:$04000125 -  StringOffset:171-4 -
#23=pos3.X   Class:1 - Class:2 -  Stack:18 -  Hash:$060001AB -  StringOffset:176-6 -
#24=pos3.Y   Class:1 - Class:2 -  Stack:19 -  Hash:$060001AC -  StringOffset:183-6 -
#25=pos3.Z   Class:1 - Class:2 -  Stack:20 -  Hash:$060001AD -  StringOffset:190-6 -
#26=Speed3   Class:1 - Class:101 -  Stack:21 -  Hash:$060001A4 -  StringOffset:197-6 -
#27=Speed3.X   Class:1 - Class:2 -  Stack:21 -  Hash:$0800022A -  StringOffset:204-8 -
#28=Speed3.Y   Class:1 - Class:2 -  Stack:22 -  Hash:$0800022B -  StringOffset:213-8 -
#29=Speed3.Z   Class:1 - Class:2 -  Stack:23 -  Hash:$0800022C -  StringOffset:222-8 -
#30=Cross3   Class:1 - Class:101 -  Stack:24 -  Hash:$060001BD -  StringOffset:231-6 -
#31=Cross3.X   Class:1 - Class:2 -  Stack:24 -  Hash:$08000243 -  StringOffset:238-8 -
#32=Cross3.Y   Class:1 - Class:2 -  Stack:25 -  Hash:$08000244 -  StringOffset:247-8 -
#33=Cross3.Z   Class:1 - Class:2 -  Stack:26 -  Hash:$08000245 -  StringOffset:256-8 -
#34=Normal3   Class:1 - Class:101 -  Stack:27 -  Hash:$070001FC -  StringOffset:265-7 -
#35=Normal3.X   Class:1 - Class:2 -  Stack:27 -  Hash:$09000282 -  StringOffset:273-9 -
#36=Normal3.Y   Class:1 - Class:2 -  Stack:28 -  Hash:$09000283 -  StringOffset:283-9 -
#37=Normal3.Z   Class:1 - Class:2 -  Stack:29 -  Hash:$09000284 -  StringOffset:293-9 -
#38=~VEC30000   Class:1 - Class:101 -  Stack:30 -  Hash:$0900024F -  StringOffset:303-9 -
#39=~VEC30000.X   Class:1 - Class:2 -  Stack:30 -  Hash:$0B0002D5 -  StringOffset:313-11 -
#40=~VEC30000.Y   Class:1 - Class:2 -  Stack:31 -  Hash:$0B0002D6 -  StringOffset:325-11 -
#41=~VEC30000.Z   Class:1 - Class:2 -  Stack:32 -  Hash:$0B0002D7 -  StringOffset:337-11 -



---[ BYTE CODE VIEW ]---------------------------------

#0>> Move Value [0] = [$00000000$40590000]Val=100.0
#16>> Move Value [1] = [$00000000$40690000]Val=200.0
#32>> MULT [2] = [0] * [1]
#48>> Move Value [8] = [$00000000$3FF00000]Val=1.0
#64>> Move Value [9] = [$00000000$40000000]Val=2.0
#80>> Move [0] = [8]
#92>> Add [13].Vector2 = [6].Vector2 , [8].Vector2
#108>> Copy [6] = [13]+ [2]
#124>> Sub [13].Vector2 = [6].Vector2 , [8].Vector2
#140>> Copy [6] = [13]+ [2]
#156>> Mult [13].Vector2 = [6].Vector2 , [8].Vector2
#172>> Copy [6] = [13]+ [2]
#188>> Div [13].Vector2 = [6].Vector2 , [8].Vector2
#204>> Copy [6] = [13]+ [2]
#220>> [0] = COS( [1])
#236>> [13] = GetNormal2D( [8])
#252>> Copy [10] = [13]+ [2]
#268>> [5] = GetLength2D( [8])
#284>> [0] = GetDotProduct2D( [6],[8])
#304>> [0] = GetCrossProduct2D( [6],[8])
#324>> Move Value [8] = [$00000000$40690000]Val=200.0
#340>> Move Value [9] = [$00000000$40590000]Val=100.0
#356>> [13] = GetNormal2D( [8])
#372>> Copy [15] = [13]+ [2]
#388>> [13] = GetNormal2D( [8])
#404>> Copy [10] = [13]+ [2]
#420>> Move Value [18] = [$00000000$40590000]Val=100.0
#436>> Move Value [19] = [$00000000$40690000]Val=200.0
#452>> Move Value [20] = [$00000000$4072C000]Val=300.0
#468>> Move Value [21] = [$00000000$3FF00000]Val=1.0
#484>> Move Value [22] = [$00000000$40000000]Val=2.0
#500>> Move Value [23] = [$00000000$40080000]Val=3.0
#516>> Add [30].Vector3 = [18].Vector3 , [21].Vector3
#532>> Copy [18] = [30]+ [3]
#548>> Mult [30].Vector3 = [18].Vector3 , [21].Vector3
#564>> Copy [18] = [30]+ [3]
#580>> Div [30].Vector3 = [18].Vector3 , [21].Vector3
#596>> Copy [18] = [30]+ [3]
#612>> Sub [30].Vector3 = [18].Vector3 , [21].Vector3
#628>> Copy [18] = [30]+ [3]
#644>> [5] = GetLength3D( [18])
#660>> [17] = GetDotProduct3D( [18],[21])
#680>> [30] = GetCrossProduct3D( [18],[21])
#700>> Copy [24] = [30]+ [3]
#716>> [30] = GetNormal3D( [18])
#732>> Copy [27] = [30]+ [3]
#748>> END


---[ LAST EXPRESSION TABLE ]---------------------------------

#0  Token=1012 -  SrcIndex=308 -  Stack=30 -  LiteralData=$00000000$00000000


---[ EXECUTION  ]---------------------------------

  252 Ticks TO Execute [1000000] Times  
  47 Instructions in byte code
 Approx 186.5079 MILLION 64bit Opcodes Per Second


  129 Ticks - Read / Write Variable Result [1000000] Times  


0
---[ VARIABLES POINTER ]---------------------------------

[Result] Variable Ptr=0
[Result] Variable Flt=0.0


---[ VARIABLES ]---------------------------------

A=0.0
B=200.0
C=20000.0
D=0.0
E=0.0
Size=40700.0
Pos=0.0
Pos.X=0.0
Pos.Y=0.0
Speed=200.0
Speed.X=200.0
Speed.Y=100.0
SpeedNormal=0.8944271909999158
SpeedNormal.X=0.8944271909999158
SpeedNormal.Y=0.4472135954999579
~TEMP0000=0.0
~VEC20000=0.8944271909999158
~VEC20000.X=0.8944271909999158
~VEC20000.Y=0.4472135954999579
nx=0.8944271909999158
ny=0.4472135954999579
DotProduct3=1400.0
pos3=100.0
pos3.X=100.0
pos3.Y=200.0
pos3.Z=300.0
Speed3=1.0
Speed3.X=1.0
Speed3.Y=2.0
Speed3.Z=3.0
Cross3=0.0
Cross3.X=0.0
Cross3.Y=0.0
Cross3.Z=0.0
Normal3=0.4445542244743870
Normal3.X=0.4445542244743870
Normal3.Y=0.8891084489487740
Normal3.Z=1.333662673423161
~VEC30000=0.4445542244743870
~VEC30000.X=0.4445542244743870
~VEC30000.Y=0.8891084489487740
~VEC30000.Z=1.333662673423161






   252 Ticks TO Execute [1000000] Times  
  47 Instructions in byte code
 Approx 186.5079 MILLION 64bit Opcodes Per Second



PlayBASIC Math64  V007 - Public Test  (2020-12-19)

   Here's today WIP build which includes basic Vector2 and Vector3 support.

   if you have ideas for more functions/ operations, then the quickest way forward would be for you to write some examples and i'll just slot them in the best I can.


   Video

 





  Download
 
     Attached.

Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on January 20, 2021, 03:38:26 AM
PlayBASIC LIVE -  MATH64  - Version 8 Update - (2021-01-20)

  A quick look over how scripts can be handled in Build 8 of the Math64 library.     The idea allows scripts be part of the main source code but be loaded and parsed/compiled when the program in executed.  
 




  Sample script example.

[pbcode]

; PROJECT : PB64 - 64Bit Library test
; EDITED  : 20/01/2021
; ---------------------------------------------------------------------



#if _Ignore_Math64_SCRIPTS


Function Math64Script_AddVectors2()
   
//  -------------------------------------------------
//  -----------[ VEcTOR EXAMPLE ]--------------------
//  -------------------------------------------------


   var A,B,C,D,E, Size
   
   vector2  Pos, Speed, SpeedNormal


   A    = 100
   B   =200
   C   = A * B
   speed.x = 1
   speed.y = 2

   a = Speed.X   

    pos = pos + Speed
    pos = pos - Speed
    pos = pos * Speed
    pos = pos / Speed


   a = cos(b)


   //  Compute normal from Speed vector
   SpeedNormal   = GetNormal2D(Speed)

   //  get the length / size of this vector
   Size      = GetLength2D(Speed)


   a = GetDotProduct2D(Pos,Speed)   

   // this is if a bit iffy in 2D
   a = GetCrossProduct2D(Pos,Speed)   

   // ------------------------------------------------------
   //  copy the normal vector to variables NX + NY   
   // ---------------------------------------------------------

   // declare pair of variables
   var nx,ny

   // Set the speed vector
   Speed.X = 200
   Speed.Y = 100

   // compute normal from Speed and write to NX and NY variables
   Nx = getNormal2D(Speed)

   // Compute normal and write result to the SpeedNormal vector
   SpeedNormal = getNormal2D(Speed)



   // ------------------------------------------------------
   //  TEST VECTOR3 OPERATIONS
   // ---------------------------------------------------------

   var DotProduct3
   vector3 pos3, Speed3, Cross3, Normal3

   pos3.x = 100
   pos3.y = 200
   pos3.z = 300

   speed3.x = 1
   speed3.y = 2
   speed3.z = 3

   pos3 = pos3 + Speed3
   pos3 = pos3 * Speed3
   pos3 = pos3 / Speed3
   pos3 = pos3 - Speed3

   //  
   Size          = GetLength3D(pos3)
   dotProduct3 = GetDotProduct3d(pos3,speed3)
   Cross3       = GetCrossProduct3d(pos3,speed3)   
   Normal3      = getNormal3D(pos3)

   
   
EndFunction



Function Math64Script_IF_Example()


// ----------------------------------------------------
//  IF - EXAMPLE SCRIPT
// ----------------------------------------------------

      Var A,B,C,D,E,F      
      VaR Result,s,count         
      VaR CopyOfResult         

      // a = cos(100,50)   

      //a = 405+wobble
      // This is aa comment

      A=50+50                  
      B = (A=100.0)

      if C<>0                  
         C=123.456               
      endif                     

      if D=0 and B=1                  
          D=123456.678               
      endif                     


      if D>1000                  
         if B=1                  
           E=5544.11            
         endif                  
      endif
                     
      
      if D<1000                  
          E=1                  
        else            
          E=2                  
      endif                     
      
      
      if D>1000                  
          F=1                  
        else            
          F=2                  
      endif                     
      
      

EndFunction


#endif




/*

[SCRIPT]

//  -------------------------------------------------
//  -----------[ VEcTOR EXAMPLE ]--------------------
//  -------------------------------------------------


   var A,B,C,D,E, Size
   
   vector2  Pos, Speed, SpeedNormal


   A = 100
   B=200
   C= A * B
   speed.x = 1
   speed.y = 2

   a = Speed.X   

    pos = pos + Speed
    pos = pos - Speed
    pos = pos * Speed
    pos = pos / Speed


   a = cos(b)


   //  Compute normal from Speed vector
   SpeedNormal   = GetNormal2D(Speed)

   //  get the length / size of this vector
   Size      = GetLength2D(Speed)


   a = GetDotProduct2D(Pos,Speed)   

   // this is if a bit iffy in 2D
   a = GetCrossProduct2D(Pos,Speed)   

   // ------------------------------------------------------
   //  copy the normal vector to variables NX + NY   
   // ---------------------------------------------------------

   // declare pair of variables
   var nx,ny

   // Set the speed vector
   Speed.X = 200
   Speed.Y = 100

   // compute normal from Speed and write to NX and NY variables
   Nx = getNormal2D(Speed)

   // Compute normal and write result to the SpeedNormal vector
   SpeedNormal = getNormal2D(Speed)



   // ------------------------------------------------------
   //  TEST VECTOR3 OPERATIONS
   // ---------------------------------------------------------

   var DotProduct3
   vector3 pos3, Speed3, Cross3, Normal3

   pos3.x = 100
   pos3.y = 200
   pos3.z = 300

   speed3.x = 1
   speed3.y = 2
   speed3.z = 3

   pos3 = pos3 + Speed3
   pos3 = pos3 * Speed3
   pos3 = pos3 / Speed3
   pos3 = pos3 - Speed3

   //  
   Size = GetLength3D(pos3)
   dotProduct3 = GetDotProduct3d(pos3,speed3)
   Cross3       = GetCrossProduct3d(pos3,speed3)   
   Normal3   = getNormal3D(pos3)


[/SCRIPT]

   */

[/pbcode]



   Syntax Hilighter PLI file Example

     
Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: stevmjon on January 21, 2021, 08:02:14 PM
out of interest kev, have you found any bugs in PB while coding 64bit math, or made any improvements that you may not have found if you didn't to the 64bit math?

you have put a lot of time into this now, so i hope PB itself has benefited also, as well as having this feature added.
and... i hope you have enjoyed this journey too.
Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on January 21, 2021, 10:49:23 PM
Quote from: stevmjon on January 21, 2021, 08:02:14 PM
out of interest kev, have you found any bugs in PB while coding 64bit math, or made any improvements that you may not have found if you didn't to the 64bit math?

  yeah generally do, using it is the best way to find missing/broken stuff. .  but I don't think this round revealed too many obvious show stoppers.  Although one that comes to mind is the dim & redim was missing a slab of code to actually mange the buffers.  Stuff that was on a to-do-list long ago have since been forgotten.

Quoteyou have put a lot of time into this now, so i hope PB itself has benefited also, as well as having this feature added.
and... i hope you have enjoyed this journey too.

  hard to say, it's an interesting subject..  what is and what is not for the benefit of this thing called PB.  

Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on January 27, 2021, 10:31:46 PM

PlayBASIC LIVE -  MATH64  - Version 8 - GUI Interface - (2021-01-28)


      Here's the current WIP of the Math64 library, pictured is the math 64b library being used from a bit of the simple front end this time.    There's two ways of the using the libary the low level (as you've already seen) and a set of higher level functions to manage scripts on your behalf.


      In the picture you can see a simple interface (in this demo) showing a syntax highlighted version of the script,  and the variable status.   

Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on January 28, 2021, 09:11:03 PM
PlayBASIC Math64  V008 - Public Test  (2021-01-29)

   Here's build 8, this one transforms the 'test' into something more like a normal PlayBASIC library of functions that can be included and used through out other programs, as such we've now got some double up, with there being the original low level functions and second higher level set of functions for most user will use for simplicity.  These functions all you to load a script / compile and run it from a few function calls..


 
Math64 User (High level) functions:


            Index=NewPB64Script(Name$,code$="")
            Status=CompilePB64Script(Index)
            ExecutePB64Script(Index)
            DeletePB64Script(Index)



            Name$=GetPB64ScriptName(Index)

            Code$=GetPB64ScriptCode(Index)

            Filename$=GetPB64ScriptFileName(Index)
            Count=GetPB64ScriptFileVariableCount(Index)
            Name$=GetPB64ScriptVariableName(Index,VariableIndex)
            Value$=GetPB64ScriptVariableValue$(Index,VariableIndex)


            Status=GetPB64ScriptStatus(Index)
            Count=GetPB64ScriptQuantity()


                    // Parse a PLAYBASIC source code as Script at RUNTIME

            LoadSourceAsPB64Script(SourceCodeFilename$)
                                    This function will search the source file for functions with the  Function Math64Script_ and grab the text and load it as a Script using NewPB64Script()  as above.


[pbcode]
#if _Ignore_Math64_SCRIPTS

   //  Code inside this directive will be ignored by PlayBASIC, so we can HIDE scripts (or other data) within PBA files directly from within the IDE
Function Math64Script_NAME_OF_YOUR_SCRIPT_HERE()

EndFunction

#Endif
[/pbcode]

            Text$=PB64_LoadTextFileToString(File$)



   Note: Function Names are subject to change..  



 
Video


 




 
Download

 
     Attached.

Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on February 03, 2021, 06:30:55 PM
PlayBASIC Math64  V009 - Public Test  (2021-02-05)

   Here's build 9, which introduces our infamous particle demo to the test kit.   Not without issues though, but that's a good thing,  as during development of the particle demo I've found some obvious missing functionality in the math64 compiler,  which will be addressed in the next build.   But for now you can work around them,  which is things like comparisons not parsing correctly in regards to vector fields..

   In the video bellow I take you through the current implementation and few ideas on improvements to it,  but for now the big question is about speed..  Is it faster than native PB ..   watch the video to find out !




 
Math64 User (High level) functions:


            Index=NewPB64Script(Name$,code$="")
            Status=CompilePB64Script(Index)
            ExecutePB64Script(Index)
            DeletePB64Script(Index)



            Name$=GetPB64ScriptName(Index)

            Code$=GetPB64ScriptCode(Index)

            Filename$=GetPB64ScriptFileName(Index)
            Count=GetPB64ScriptFileVariableCount(Index)
            Name$=GetPB64ScriptVariableName(Index,VariableIndex)
            Value$=GetPB64ScriptVariableValue$(Index,VariableIndex)


            Status=GetPB64ScriptStatus(Index)
            Count=GetPB64ScriptQuantity()


                    // Parse a PLAYBASIC source code as Script at RUNTIME

            LoadSourceAsPB64Script(SourceCodeFilename$)
                                    This function will search the source file for functions with the  Function Math64Script_ and grab the text and load it as a Script using NewPB64Script()  as above.


[pbcode]
#if _Ignore_Math64_SCRIPTS

   //  Code inside this directive will be ignored by PlayBASIC, so we can HIDE scripts (or other data) within PBA files directly from within the IDE
Function Math64Script_NAME_OF_YOUR_SCRIPT_HERE()

EndFunction

#Endif
[/pbcode]

            Text$=PB64_LoadTextFileToString(File$)



   Note: Function Names are subject to change..  



 
Video


 




 
Download

 
     Attached.
Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on February 05, 2021, 08:33:25 AM
PlayBASIC Math64  V009b - Public Test  (2021-02-05)

   Here's build 9b, fixes the literal problem and adds a few new functions.


 
Download

 
     Attached.
Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on April 06, 2021, 10:43:04 PM
PlayBASIC LIVE -  Math64 -  Lexing and Revision 2021  (2021-04-06 )


  This is more a recap I guess but we do look at Math64 it's Syntactical lexer, talk about things we could do with it and at the end check out some releases from revision 2021








[Downloads & Links]


   Revision 2021  (Demo Competition)  (Amiga - PC) (https://www.underwaredesign.com/forums/index.php?topic=4579.0)




[Credits]


     Video By:
  Kevin Picone
  http://PlayBASIC.com  
  https://Underwaredesign.com

  Music:
 Spirit of Fire by  Jesse Gallagher


[Links]


PlayBASIC LIVE PLAYLIST
https://www.youtube.com/playlist?list=PL_dvm0gvzzIVGlAhx34N6z2ce0ffMMOZ8

PlayBASIC BLOG PLAYLIST
https://www.youtube.com/playlist?list=PL_dvm0gvzzIU0Hnr6veV5UvwkSapHCo1J

PlayBASIC on FACEBOOK
http://www.facebook.com/pages/PlayBasic/127905400584274   (Facebook Page)

PlayBASIC on TWITTER
https://twitter.com/PlayBasic



#PlayBASIC #coding #basic #sourcecode #64bit #revision #demos #Amiga
Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on April 08, 2021, 11:40:06 AM
  PlayBASIC Math64  V010 - WIP   (2021-04-09)

      Tweaking the lexer up to support remark blocks /* and */  pairs,  it also supporting nesting them as well as within expressions,  unlike PB ..  


   [pbcode]


Function Math64Script_ProcessParticle()


         //  float64 status
         var status
         vector2 Pos,Speed
         
         // Add the particles speed to the          
         Pos=Pos+Speed
         
         //  Apply gravity to speed
         Speed.Y = Speed.Y + /*This is /*a*/ comment*/0.255  
         
      //   Status=0
         
         if range(pos.x,0,799) /*                  
            Status=(pos.y=>599)
            if (pos.y<0)
                  Status=2
            endif
         else      */      
            Status=1               
         endif         
                        
                  
EndFunction


Function Math64Script_TestSyntaxHighLighter()

1234
/**/
5678
      1234/**/5678
      1234/*a*/5678
      1234/*ab*/5678
      1234/*abc*/5678
      1234/*abcd*/5678
   
   // Multi Line Comments
   /*
   */1+2+3+4

   if 9999/*
         0x0123456789abcdef
1+2+3+4
         0c01234567+1234
1+2+3+4
         rem
1+2+3+4         
         rem This is a 1111 remark
1+2+3+4         

         ;
1+2+3+4         
         ; single line comment
1+2+3+4         
         //
1+2+3+4         
         //  float64 status
1+2+3+4         
         var status
         vector2 Pos,Speed
         // Add the particles speed to the          
         Pos=Pos+Speed
         
         //  Apply gravity to speed
         Speed.Y = Speed.Y + 0.255  
         
      //   Status=0
         if range(pos.x,0,799)                  
            Status=(pos.y=>599)
            if (pos.y<0)
                  Status=2
            endif
         else            
            Status=1               
         endif         
                        
         ""+"a"+"BB"+"BBB"+"CCC"+"DDD"
         "Hello" + "World"
         
         $a+$bb+$cc+$ddd+$eeee+$ffff+$aabbccdd/12345
         %1010101011
         %1=%00+%111+%000
   */11+22                  
EndFunction


   [/pbcode]
Title: Re: 64Bit Floating Point Math Library for PlayBASIC (Dev Blog)
Post by: kevin on April 16, 2021, 10:20:58 AM
  PlayBASIC Math64  V010 - Public Test   (2021-04-17)

      This build see's greater parsing abilities in Scripts with additions like nested single and multi line comments,  inclusion of white space and ExitSCRIPT() function/command and bunch of tweaks no doubt


      Here's the updated particle script.  
   [pbcode]

Function Math64Script_ProcessParticle()

         remstart
            -------------------------------------------------
            ---------[ Process Particles Script ]------------
            -------------------------------------------------
         remend

         //  float64 status
         var status  
         vector2 Pos /* Can I Have remstart Inline remend comments here*/, Speed

         // Add the particles speed to the          
         Pos=Pos+/* remark inside expression*/Speed
         
         //  Apply gravity to speed
         Speed.Y   =Speed.Y+0.255    

         if range(pos.x,0,799)            
            if (pos.y<0)
                  ExitScript(2)
            endif
            ExitScript((pos.y=>599))
         else            
            //  Delete if this is outside the viewports X bounds   
            ExitScript(1)
         endif         
                        
EndFunction

   [/pbcode]



PlayBASIC LIVE - MATH64 Version 10 - (2021-04-17)


   





Download