News:

Function Finder  Find all the functions within source code files

Main Menu

64Bit Floating Point Math Library for PlayBASIC (Dev Blog)

Started by kevin, July 20, 2020, 08:31:54 AM

Previous topic - Next topic

kevin

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.

PlayBASIC Code: [Select]
; 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
Login required to view complete source code




   Syntax Hilighter PLI file Example

     

stevmjon

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.
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin

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.  


kevin


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.   


kevin

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.


PlayBASIC Code: [Select]
 #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



            Text$=PB64_LoadTextFileToString(File$)



   Note: Function Names are subject to change..  



 
Video


 




 
Download

 
     Attached.


kevin

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.


PlayBASIC Code: [Select]
 #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



            Text$=PB64_LoadTextFileToString(File$)



   Note: Function Names are subject to change..  



 
Video


 




 
Download

 
     Attached.

kevin

PlayBASIC Math64  V009b - Public Test  (2021-02-05)

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


 
Download

 
     Attached.

kevin

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)




[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

kevin

  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 ..  


   
PlayBASIC Code: [Select]
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




kevin

  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.  
   
PlayBASIC Code: [Select]
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






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


   





Download