News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

FreeBasic Runtime Library test

Started by guga, February 22, 2022, 06:07:12 PM

Previous topic - Next topic

guga

Hi Guys

Good to know it´s working Vortex  :thumbsup: :thumbsup:

Jack, i found out why it was not working during my last test of compiling during the morning. On the 1st or 2nd line of the batch file, gcc outputed hundreds of object files starting with "duecs000xxx.o" that was causing linker problems of duplicated symbols etc. This time, what i did was simply delete those file and compile it again. :smiley: :smiley:

About the removal of DATA, it didn´t worked. I did this:

1- Created the normal dll with  "DllCreator.bat"
2 - Deleted all "ducs000xxx.o" generated by the gcc linker
3 - Edited manually the def file removing the DATA from it and saved it as "FbRtl32N.def" containing this new list of exports (renumbered):
EXPORTS
    fb_ASC@8 @1
    fb_AllocateMainFBThread @2
    fb_ArrayBoundChk@20 @3
    fb_ArrayClear@4 @4
    fb_ArrayClearObj@12 @5
    fb_ArrayDestructObj@8 @6
    fb_ArrayDestructStr@4 @7
    fb_ArrayErase@4 @8
    fb_ArrayEraseObj@12 @9
    fb_ArrayGetDesc@4 @10
    fb_ArrayLBound@8 @11
    fb_ArrayLen@4 @12
    fb_ArrayRedimEx @13
    fb_ArrayRedimObj @14
(....)


4 - Created another batch file and on the 4th line (used by dlltool.exe) i settled it to use FbRtl32N.def instead FbRtl32.def. So, the new batch file resulted in:
C:\msys64\mingw32\bin\gcc.exe -o FbRtl32D.dll *.o -shared -static -lgdi32 -lwinspool -lffi -lwinmm -Wl,--subsystem,windows
C:\msys64\mingw32\bin\gcc.exe -o FbRtl32.dll *.o -shared -static -lgdi32 -lwinspool -lffi -lwinmm -Wl,--subsystem,windows,--output-def,FbRtl32.def
C:\msys64\mingw32\bin\gcc.exe -o FbRtl32.dll *.o -shared -static -lgdi32 -lwinspool -lffi -lwinmm -Wl,--subsystem,windows,--kill-at
C:\msys64\mingw32\bin\dlltool.exe --kill-at -d FbRtl32N.def -D FbRtl32.dll -l FbRtl32.a
pause


5 - Runned the new batch file again, but the Data exports are still there. What i´m doing wrong ? There´s a special token in the def file or gcc command to we exclude specific exports to be created ?
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jack

honestly I don't know but it puzzles me why editing the def didn't work, the way I see it the data is by the functions and def  file is only needed to build the import lib

jack

just in case anyone wants to try my build of the FB runtime dlls

jack


guga

Great work, Jack :thumbsup: :thumbsup: :thumbsup:

Guys, i´m suceeding to port the FB LolRemez version, and as soon i finish i´ll upload it here. One question...
Anybody knows the commands used in FB version of LolRemez ? I`m using thde default command poly "-6,8,cos(x)*sin(x)"  to test the app, but i needed more examples of usage to see if the port i did was correct.


In his version he uses some math or logical  operations such as Not, and, or xor, / * , \ etc. Someone have a example of using those ? And...are those commands on FB version the same as the ones in the original from github ?
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jack

Hi guga
dodicat's code is not related to lolremez on GitHub
in the example you posted  "-6,8,cos(x)*sin(x)" the first 2 numbers are the range that the function will be approximated, in his program, pressing the return key will increase the degree of the polynomial and approximate the function again to the higher degree, pressing the escape key exits the program
you can try any number of functions and operators for your function, for example "0,1,exp(x)" will approximate the exp function in the range 0 to 1

guga

I Don´t get it. So what is the correct (Most accurate) app to use ? Dodicat´s, LolRemez or a new version of Dodicat ?

I saw on FB forum another discussion about it and with another solution of Dodicat using minmax
https://www.freebasic.net/forum/viewtopic.php?p=280855&hilit=lolremez#p280855




Sub GaussJordan(matrix() As Double,rhs() As Double,ans() As Double)
      Dim As Long n=Ubound(matrix,1)
      Redim ans(0):Redim ans(1 To n)
      Dim As Double b(1 To n,1 To n),r(1 To n)
      For c As Long=1 To n 'take copies
            r(c)=rhs(c)
            For d As Long=1 To n
                  b(c,d)=matrix(c,d)
            Next d
      Next c
      #macro pivot(num)
      For p1 As Long  = num To n - 1
            For p2 As Long  = p1 + 1 To n 
                  If Abs(b(p1,num))<Abs(b(p2,num)) Then
                        Swap r(p1),r(p2)
                        For g As Long=1 To n
                              Swap b(p1,g),b(p2,g)
                        Next g
                  End If
            Next p2
      Next p1
      #endmacro
      For k As Long=1 To n-1
            pivot(k)              'full pivoting each run
            For row As Long =k To n-1
                  If b(row+1,k)=0 Then Exit For
                  Var f=b(k,k)/b(row+1,k)
                  r(row+1)=r(row+1)*f-r(k)
                  For g As Long=1 To n
                        b((row+1),g)=b((row+1),g)*f-b(k,g)
                  Next g
            Next row
      Next k
      'back substitute
      For z As Long=n To 1 Step -1
            ans(z)=r(z)/b(z,z)
            For j As Long = n To z+1 Step -1
                  ans(z)=ans(z)-(b(z,j)*ans(j)/b(z,z))
            Next j
      Next    z
End Sub

'Interpolate through point via a polynomial (spline)
Sub Interpolate(x_values() As Double,y_values() As Double,p() As Double)
      Var n=Ubound(x_values)
      Redim p(0):Redim p(1 To n)
      Dim As Double matrix(1 To n,1 To n),rhs(1 To n)
      For a As Long=1 To n
            rhs(a)=y_values(a)
            For b As Long=1 To n
                  matrix(a,b)=x_values(a)^(b-1)
            Next b
      Next a
      'Solve the linear equations
      GaussJordan(matrix(),rhs(),p())
End Sub

Function polyval(Coefficients() As Double,Byval x As Double) As Double
      Dim As Double acc
      For i As Long=Ubound(Coefficients) To Lbound(Coefficients) Step -1
            acc=acc*x+Coefficients(i)
      Next i
      Return acc
End Function

Sub chebypoints(min As Double,max As Double,order As Integer,c()As Double)
      Redim c(1 To order)
      Dim pi As Double=4*Atn(1)
      Dim count As Integer
      For k As Integer=order To 1 Step -1
            count=count+1
            c(count)= Cos((pi/2)*(2*k-1)/order)
            c(count)=(max-min)*(c(count)+1)/2+min
      Next k
      Print "chebychev points in range"
      For n As Long=Lbound(c) To Ubound(c)
            Print n,c(n)
      Next
      Print
End Sub

Function nest(pol() As Double) As String
      Dim As String xx,tmp,ch=""
      For a As Long=Ubound(pol) To Lbound(pol) Step -1
            Dim As String op
            If a=Lbound(pol) Then xx="" Else xx="*x"
            Dim As Double p=pol(a)
            If Sgn(p)>=0 Then op="+" Else op=""
            tmp="("+ch+op+Str(p)+")"+xx
            ch="("+ch+op+Str(p)+")"+xx
            If Len(tmp)>50 Then ch=ch+" _ " +Chr(10) '80
      Next a
      Return ch
End Function

Function func(x As Double) As Double
return (((((-0.01019205450473583)*x+0.08530805745877951)*x-0.3142876923553593)*x _
+0.9127809568362455)*x _
+0.3264033259436233)
End Function

Dim As Long n=5 '<----------------------  number of terms
Dim As Double lowerx=1 '<-----------------  LIMITS
Dim As Double upperX=2 '<------------------ LIMITS

Dim As Double x(1 To 5)
Dim As Double y(1 To 5)

Redim As Double points()
lowerx=1
upperx=2

chebypoints(lowerX,upperX,n,points())
For z As Double=1 To 5
      x(z)=points(z)
      y(z)=sqr(points(z))
Next
Redim As Double Poly(0)
interpolate(x(),y(),poly())

Print "Polynomial Coefficients:"
Print
For z As Long=1 To Ubound(Poly)
      If z=1 Then
            Print "constant term  ";Tab(20);Poly(z)
      Else
            Print Tab(8); "x^";z-1;"   ";Tab(20);Poly(z)
      End If
Next z
Print
Print "nested form:"
Print nest(poly())
Print


Print "  x           sqrt(1+x)                error"
For x As Double=0 To 1.05 Step 0.1
      Var y=func(1+x)
      Print Using "##.###";x;
      Print "  ";y, y-Sqr(1+x)
Next

Sleep


What versions are the correct ones ?
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jack

I don't use his code so I can't help you there, but while his code works to some extent it's limited because of it's use of double precision, if you wanted to approximate your function for single precision then it's probably good enough but if you want higher precision approximation then use something else, the lolremez from GitHub is better but I wouln't use that either
rational minimax approximations are usually more accurate, I would recommend Mathematica and you get it for free on the Raspberry PI, for example here's an approximation to log(1+x) in the range 0 to 1

(x (2569.904056423691126968 +
     x (5756.381534657531664647 +
        x (4502.370849703438634267 +
           x (1456.290562569254837547 +
              x (176.9521118930255743703 +
                 5.235866454158384429507 \
x))))))/(2569.904056423691455251 +
   x (7041.333562869242358112 +
      x (7166.402945672550756556 +
         x (3334.856861651063659714 +
            x (701.9321435126277119667 +
               x (56.23432384224838579736 + x))))))

maximum relative error -1.27741479491948110288e-16

guga

H Guys

The Dodicat[s lolremez version is running now with the FBRTl32.dll  :thumbsup: :thumbsup: :azn: :azn: :azn:




It still have some flaws, but i[m working on it. The graphic part seems to work ok, now i need to fix a bit more to show the lines etc.

Jack...I do[t know about mathematica. I wanted to build a standalone version for us to use, So, mathematica don't have a library to use that fits our purposes. Also, it seems that it´s not free anymore
https://community.wolfram.com/groups/-/m/t/1511397


About "rational minimax approximations". Isn´t that what Dodicat did on his last post ? If not..how to implement this minimax approximations ?
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jack

that post on the wolfram groups is 3 years old, I just installed Mathematica on my PI 4 about a week ago, I don't know how you would implement rational minimax sorry, perhaps one the math experts can you some advise
nmerical recipes has code to do rational chebyshev approximation http://phys.uri.edu/nigh/NumRec/bookfpdf/f5-13.pdf