FreeBASIC 1.09.0 Release

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
coderJeff
Site Admin
Posts: 4269
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

FreeBASIC 1.09.0 Release

Post by coderJeff »

Update 2022.01.01:
News Post: FreeBASIC 1.09.0 is released!

Jump to the post in this discussion on the 1.09.0 release


----
Development on fbc 1.08.1 and fbc 1.09.0 started June 2021.

For discussions on bugs / development, there is also:
- Issue tracker on github: https://github.com/freebasic/fbc/issues
- Bug tracker on sourceforge.net: https://sourceforge.net/p/fbc/bugs/

For discussion on the 1.08.x release see: FreeBASIC 1.08.x Release Discussion

Previous development discussion:
- See FreeBASIC 1.08.0 Development as there are likely several posts that should be linked and carried forward since there were many requests and reports not tracked anywhere else.

In the immediate future:
- fix the worst bugs from the 1.08.0 release and get a 1.08.1 release or snapshot out (soon-ish).

Big stuff that should be next in 1.09.0:
- rtlib coded in fb (revival of project started by Imortis)
- variable length wstring
- 'On error goto' is seriously broken - like it needs to be fixed or removed
- FreeBSD seems close to having a full package - need to validate
- tooling and testing for the emscripten feature is incomplete - it's currently not user friendly

Releases:
- Need to improve the frequency of releases. Maybe something like package snapshots for select targets. If users are only comfortable with full packages I'd like them to have the opportunity to test out new features more often and participate in the development process.

For developers:
- fbc/fbc-1.08 branch currently on version 1.08.1 is for bug fixes
- fbc/master branch currently on version 1.09.0 is for new stuff
- previously when managing the 1.07.x branch and master (1.08.0) branch I was using a rebase and cherry pick method for maintaining 2 branches. This strategy allowed for some tidy commit history but at the expense of extra preparation time for commits and breaking continuity in contributors commits.
- going forward, going to try a new strategy where bug fixes are made on the fbc-1.08 branch and merged in to the master branch. Commit history could get a little messy at times, but should require less preparation time and keep the commit history cleaner for contributors.
adeyblue
Posts: 298
Joined: Nov 07, 2019 20:08

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by adeyblue »

coderJeff wrote: - 'On error goto' is seriously broken - like it needs to be fixed or removed
A basic fix for this that I thought about (that probably has more impact than I realise is):
fb_errorSetHandler:
- do a setjmp with a buffer in the TLS and then return the value of setjmp

caller of fb_errorSetHandler:
- If the return value says we came from a longjmp, do a simple goto/jmp to the handler, otherwise continue

fb_errorThrow:
- if there's an active handler, longjmp to it

Problems:
fb_errorSetHandler currently returns the previously set handler. Not that I tested it extensively, but on Windows at least, I didn't see the return value ever being used.

Of course, without making extra effort, everything on the stack that dynamically allocates inbetween will leak
srvaldez
Posts: 3340
Joined: Sep 25, 2005 21:54

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by srvaldez »

hello FB developers
with FB 1.09 I sometimes get error 4: Duplicated definition but there's no duplicated symbol
I tried to isolate the problem in few lines of code but I am stumped, I ran into this when trying to compile some old code
so I hope that you will try the following code, hopefully it will help you find the problem in the compiler or improve the error reporting
strangely if I rename the offending variable outp to outp_ it compiles without a problem
searching the source for any other occurrences of this variable failed and there's no mention in the help of outp being a reserved keyword

Code: Select all


'*****************************
'*****************************
' BigCalc Version8.0
' written in:
' FreeBasic for windows
'
'http://www.freebasic.net
'
'*****************************
'*****************************

#define WIN_INCLUDEALL
#Include "windows.bi"
Declare Sub memclick()
Declare Sub memplusclick()

Declare Sub equalizeclick()
Declare Sub adderclick()
Declare Sub subtractorclick()
Declare Sub multiplierclick()
Declare Sub dividerclick()
Declare Sub sqrtclick()
Declare Sub sineclick()
Declare Sub cosineclick()
Declare Sub tangentclick()
Declare Sub trancendental_funct_analyzer()

Declare Sub getnumbers()
Declare Sub equalizer()
Declare Sub lessgreater()

Declare Sub adder()
Declare Sub subtractor()
Declare Sub multiplier()
Declare Sub divider()
Declare Sub dividerequalizer() 

Declare Sub squareroot()
Declare Sub sines()
Declare Sub cosines()
Declare Sub tangents()

Declare Sub clearinput1()
Declare Sub saveinput1()
Declare Sub loadinput1()
Declare Sub load_pi()

Declare Sub clearinput2()
Declare Sub saveinput2()
Declare Sub loadinput2()

Declare Sub saveoutput()
Declare Sub getfilename()

Dim Shared outtext As String
Dim Shared number1 As String
Dim Shared number2 As String
Dim Shared outsign As String * 1
Dim Shared equalized As String
Dim Shared ltgt As String * 1
Dim Shared maxlen As Ulongint
Dim Shared file As String
Dim Shared memory As String

maxlen = 1000

Dim As MSG msg
Dim Shared As HWND hWnd, calc_output, calc_input1, calc_input2, equalize, add , subtract, multiply, divide, sqrt, saveout, clear1, save1, load1, clear2, save2, load2, text1, precision, text2, text3, mem, memplus, memclear, memr1, memr2,sine,cosine,tangent,pi

' Create window
hWnd = CreateWindowEx( 0, "#32770", "BigCalc version 8.0 by Albert Redditt 8,2009-1,2010", WS_OVERLAPPEDWINDOW Or WS_VISIBLE, 100, 100, 640, 480, 0, 0, 0, 0 )

' Create output edit box
calc_output = CreateWindowEx( 0, "EDIT", "", ws_border Or WS_VISIBLE Or WS_CHILD Or WS_HSCROLL Or WS_VSCROLL Or ES_AUTOHSCROLL Or ES_AUTOVSCROLL Or ES_MULTILINE Or ES_READONLY, 10, 10, 610, 70, hWnd, 0, 0, 0 )

' Create input1 edit box
calc_input1 = CreateWindowEx( 0, "EDIT", "", ws_border Or WS_VISIBLE Or WS_CHILD Or WS_HSCROLL Or WS_VSCROLL Or ES_AUTOHSCROLL Or ES_AUTOVSCROLL Or ES_MULTILINE, 10, 180, 610, 70, hWnd, 0, 0, 0 )

' Create input2 edit box
calc_input2 = CreateWindowEx( 0, "EDIT", "", ws_border Or WS_VISIBLE Or WS_CHILD Or WS_HSCROLL Or WS_VSCROLL Or ES_AUTOHSCROLL Or ES_AUTOVSCROLL Or ES_MULTILINE, 10, 300, 610, 70, hWnd, 0, 0, 0 )


' Create buttons
equalize = CreateWindowEx( 0, "BUTTON", "Equalize"    , WS_VISIBLE Or WS_CHILD, 10 , 85 ,100, 30, hWnd, 0, 0, 0 )
add      = CreateWindowEx( 0, "BUTTON", "Add + "         , WS_VISIBLE Or WS_CHILD, 125, 85 , 70, 30, hWnd, 0, 0, 0 )
subtract = CreateWindowEx( 0, "BUTTON", "Sub - "         , WS_VISIBLE Or WS_CHILD, 200, 85 , 70, 30, hWnd, 0, 0, 0 )
multiply = CreateWindowEx( 0, "BUTTON", "Mul * "         , WS_VISIBLE Or WS_CHILD, 275, 85 , 70, 30, hWnd, 0, 0, 0 )
divide   = CreateWindowEx( 0, "BUTTON", "Div / "         , WS_VISIBLE Or WS_CHILD, 350, 85 , 70, 30, hWnd, 0, 0, 0 )
sqrt     = CreateWindowEx( 0, "BUTTON", "SqRt"           , WS_VISIBLE Or WS_CHILD, 425, 85 , 70, 30, hWnd, 0, 0, 0 )
saveout  = CreateWindowEx( 0, "BUTTON", "Save Output"    , WS_VISIBLE Or WS_CHILD, 500, 85 ,100, 30, hWnd, 0, 0, 0 )
sine     = CreateWindowEx( 0, "BUTTON", "Sine  "         , WS_VISIBLE Or WS_CHILD, 200, 120, 70, 25, hWnd, 0, 0, 0 )
cosine   = CreateWindowEx( 0, "BUTTON", "CoSine"         , WS_VISIBLE Or WS_CHILD, 275, 120, 70, 25, hWnd, 0, 0, 0 )
tangent  = CreateWindowEx( 0, "BUTTON", "Tangent"        , WS_VISIBLE Or WS_CHILD, 350, 120, 70, 25, hWnd, 0, 0, 0 )

text1    = CreateWindowEx( 0, "EDIT", "UnEqualized"   , WS_BORDER Or WS_VISIBLE Or WS_CHILD Or ES_READONLY, 10, 120, 100, 25, hWnd, 0, 0, 0 )
text2    = CreateWindowEx( 0, "EDIT", "Precision"     , WS_BORDER Or WS_VISIBLE Or WS_CHILD Or ES_READONLY, 500, 125, 100, 20, hWnd, 0, 0, 0 )
precision= CreateWindowEx( 0, "EDIT", "1000"          , WS_BORDER Or WS_VISIBLE Or WS_CHILD,                500, 150, 100, 20, hWnd, 0, 0, 0 )

text3    = CreateWindowEx( 0, "EDIT", " "      , WS_BORDER Or WS_VISIBLE Or WS_CHILD Or ES_READONLY, 165, 120, 30, 25, hWnd, 0, 0, 0 )
mem      = CreateWindowEx( 0, "BUTTON", "M"    , WS_VISIBLE Or WS_CHILD, 125, 120, 30, 25, hWnd, 0, 0, 0 )
memplus  = CreateWindowEx( 0, "BUTTON", "M+"   , WS_VISIBLE Or WS_CHILD, 125, 150, 30, 25, hWnd, 0, 0, 0 )
memclear = CreateWindowEx( 0, "BUTTON", "MC"   , WS_VISIBLE Or WS_CHILD, 165, 150, 30, 25, hWnd, 0, 0, 0 )

clear1 = CreateWindowEx( 0, "BUTTON", "Clear 1" , WS_VISIBLE Or WS_CHILD, 10 , 255, 75, 30, hWnd, 0, 0, 0 )
save1  = CreateWindowEx( 0, "BUTTON", "Save 1"  , WS_VISIBLE Or WS_CHILD, 110, 255, 75, 30, hWnd, 0, 0, 0 )
load1  = CreateWindowEx( 0, "BUTTON", "Load 1"  , WS_VISIBLE Or WS_CHILD, 210, 255, 75, 30, hWnd, 0, 0, 0 )
memr1  = CreateWindowEx( 0, "BUTTON", "M Recall", WS_VISIBLE Or WS_CHILD, 310, 255, 75, 30, hWnd, 0, 0, 0 )
pi     = CreateWindowEx( 0, "BUTTON", "PI"      , WS_VISIBLE Or WS_CHILD, 410, 255, 75, 30, hWnd, 0, 0, 0 )

clear2 = CreateWindowEx( 0, "BUTTON", "Clear 2" , WS_VISIBLE Or WS_CHILD, 10 , 375, 75, 30, hWnd, 0, 0, 0 )
save2  = CreateWindowEx( 0, "BUTTON", "Save 2"  , WS_VISIBLE Or WS_CHILD, 110, 375, 75, 30, hWnd, 0, 0, 0 )
load2  = CreateWindowEx( 0, "BUTTON", "Load 2"  , WS_VISIBLE Or WS_CHILD, 210, 375, 75, 30, hWnd, 0, 0, 0 )
memr2  = CreateWindowEx( 0, "BUTTON", "M Recall", WS_VISIBLE Or WS_CHILD, 310, 375, 75, 30, hWnd, 0, 0, 0 )

While GetMessage( @msg, 0, 0, 0 )
  TranslateMessage( @msg )
  DispatchMessage( @msg )
  
  Select Case msg.hwnd
    Case hWnd
      Select Case msg.message
        Case 273
          End
      End Select
      
    Case equalize
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            equalizeclick()
        End Select
    
    Case mem
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            memclick()
        End Select
    
    Case memplus
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            memplusclick()
        End Select
    
    Case memclear
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            memory = ""
            SetWindowText(text3," ")
        End Select

    Case precision
      Select Case msg.message  
        Case WM_KEYUP ' LBUTTONDOWN
            Dim txt As String * 20
            GetWindowText(precision , txt , sizeof(txt))
            maxlen = Val(txt)
            If maxlen > 10000000 Then 
                maxlen = 10000000
                SetWindowText(precision,Str(maxlen) )
            End If
        End Select
    
    Case add
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            adderclick()
        End Select
    
    Case subtract
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            subtractorclick()
      End Select
    
    Case multiply
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            multiplierclick()
        End Select
    
    Case divide
      Select Case msg.message  
        Case WM_LBUTTONDOWN
          dividerclick()
      End Select
    
    Case sqrt
      Select Case msg.message  
        Case WM_LBUTTONDOWN
          sqrtclick()
        End Select

    Case sine
      Select Case msg.message  
        Case WM_LBUTTONDOWN
          sineclick()
        End Select
    Case cosine
      Select Case msg.message  
        Case WM_LBUTTONDOWN
          cosineclick()
        End Select
    Case tangent
      Select Case msg.message  
        Case WM_LBUTTONDOWN
          tangentclick()
        End Select

    Case saveout
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            saveoutput()
      End Select
    
    Case clear1
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            clearinput1()
      End Select
    
    Case save1
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            saveinput1()
      End Select
    
    Case load1
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            loadinput1()
      End Select
    
    Case memr1
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            SetWindowText(calc_input1, memory)
      End Select

    Case pi
        Select Case msg.message
        Case WM_LBUTTONDOWN
            load_pi()
        End Select
    
    Case clear2
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            clearinput2()
      End Select
    
    Case save2
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            saveinput2()
      End Select
    
    Case load2
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            loadinput2()
      End Select

    Case memr2
      Select Case msg.message  
        Case WM_LBUTTONDOWN
            SetWindowText(calc_input2,memory)
      End Select
    End Select

Wend

End
'===================================
'===================================
Sub memclick()
    Dim charcount As Ulongint
    charcount = GetWindowTextLength(calc_output) + 1
    outtext = Space(charcount)
    GetWindowText(calc_output,outtext,charcount)
    outtext = trim(outtext)
    memory = outtext
    outtext = ""
    If Len(memory) >= 1 Then SetWindowText(text3,"M")
End Sub

'===================================
'===================================
Sub memplusclick()
    Dim charcount As Ulongint
    charcount = GetWindowTextLength(calc_output) + 1
    outtext = Space(charcount)
    GetWindowText(calc_output,outtext,charcount)
    outtext = trim(outtext)
    If Len(outtext) >= 1 Then
        number1 = memory
        number2 = outtext
        equalizer()
        Dim sign1 As String 
        Dim sign2 As String 
        sign1 = Left(number1,1) 
        sign2 = Left(number2,1) 
  
        lessgreater() 
  
        If sign1 = "+" And sign2 ="+" Then
            outsign = "+" 
            adder() 
        End If 
  
        If sign1 = "-" And sign2 ="-" Then
            outsign = "-" 
            adder() 
        End If 
  
        If sign1 = "-" And sign2 = "+" Then
            If ltgt = "=" Then
                outsign = "+" 
                subtractor() 
            End If 
        End If 
  
        If sign1 = "+" And sign2 = "-" Then 
            If ltgt = "="  Then
                outsign = "+" 
                subtractor() 
            End If 
        End If 
  
        If sign1 = "-" And sign2 = "+" Then 
            If ltgt = "<" Then
                outsign = "-" 
                subtractor() 
            End If 
        End If 
  
        If sign1 = "-" And sign2 = "+" Then 
            If ltgt = ">" Then
                outsign = "+" 
                Swap number1,number2 
                subtractor() 
            End If 
        End If 
  
        If sign1 = "+" And sign2 = "-" Then 
            If ltgt = "<" Then
                outsign = "+" 
                subtractor() 
            End If 
        End If 
  
        If sign1 = "+" And sign2 = "-" Then
            If ltgt = ">" Then
                outsign = "-" 
                Swap number1,number2 
                subtractor() 
            End If 
        End If 
  
        memory = outtext
        outtext = ""
        number1 = ""
        number2 = ""
        If Len(memory) >= 1 Then SetWindowText(text3,"M")
    End If
End Sub

'===================================
'===================================
Sub getnumbers()
  Dim As Ulongint charcount
  
  charcount = GetWindowTextLength(calc_input1) + 1
  number1 = Space(charcount )
  GetWindowText(calc_input1,number1, charcount ) 
  
  charcount = GetWindowTextLength(calc_input2) + 1
  number2 = Space(charcount)
  GetWindowText(calc_input2,number2, charcount) 
End Sub

'===================================
'===================================
Sub equalizeclick()
'' C) with a fb string used as buffer, so fb will allocate/free the buffer for you
  Dim As Ulongint charcount
  
  charcount = GetWindowTextLength(calc_input1) + 1
  number1 = Space(charcount )
  GetWindowText(calc_input1,number1, charcount ) 
  number1 = trim(number1)
  
  charcount = GetWindowTextLength(calc_input2) + 1
  number2 = Space(charcount)
  GetWindowText(calc_input2,number2, charcount) 
  number2 = trim(number2)
  
  equalizer() 
  SetWindowText(text1,equalized) 
  
  SetWindowText(calc_input1,number1) 
  SetWindowText(calc_input2,number2) 

  number1 = ""
  number2 = ""
End Sub 

'================================================== 
Sub adderclick() 
  Dim sign1 As String 
  Dim sign2 As String 
  Dim dec1 As Ulongint
  Dim dec2 As Ulongint
  
  getnumbers()

  sign1 = Left(number1,1)  
  Select Case sign1
    Case "-"
    Case "+"
    Case Else
        equalized = "UnEqualized"
  End Select
  
  sign2 = Left(number1,1)
  Select Case sign2
  Case "-"
  Case "+"
  Case Else
      equalized = "UnEqualized"
  End Select

  If Len(number1) <> Len(number2) Then equalized = "UnEqualized"
  dec1 = Instr(1,number1,".")
  dec2 = Instr(1,number2,".")
  If dec1 <> dec2 Then equalized = "UnEqualized"
  
  
  If equalized = "UnEqualized" Then 
    SetWindowText(calc_output ,"Equalize decimal first!") 
    Return 
  End If 

  SetWindowText(calc_output,"")

  sign1 = Left(number1,1) 
  sign2 = Left(number2,1) 
  
  lessgreater() 
  
  If sign1 = "+" And sign2 ="+" Then
    outsign = "+" 
    adder() 
  End If 
  
  If sign1 = "-" And sign2 ="-" Then
    outsign = "-" 
    adder() 
  End If 
  
  If sign1 = "-" And sign2 = "+" Then
    If ltgt = "=" Then
      outsign = "+" 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "+" And sign2 = "-" Then 
    If ltgt = "="  Then
      outsign = "+" 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "-" And sign2 = "+" Then 
    If ltgt = "<" Then
      outsign = "-" 
      subtractor() 
    End If 
  End If 
  If sign1 = "-" And sign2 = "+" Then 
    If ltgt = ">" Then
      outsign = "+" 
      Swap number1,number2 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "+" And sign2 = "-" Then 
    If ltgt = "<" Then
      outsign = "+" 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "+" And sign2 = "-" Then
    If ltgt = ">" Then
      outsign = "-" 
      Swap number1,number2 
      subtractor() 
    End If 
  End If 
  
  SetWindowText(calc_output ,outtext) 
  outtext = ""
  number1 = ""
  number2 = ""
End Sub 
'================================================== 
Sub subtractorclick() 
  Dim sign1 As String 
  Dim sign2 As String
  Dim dec1 As Ulongint
  Dim dec2 As Ulongint
  
  getnumbers()

  sign1 = Left(number1,1)  
  Select Case sign1
    Case "-"
    Case "+"
    Case Else
        equalized = "UnEqualized"
  End Select
  
  sign2 = Left(number1,1)
  Select Case sign2
  Case "-"
  Case "+"
  Case Else
      equalized = "UnEqualized"
  End Select

  If Len(number1) <> Len(number2) Then equalized = "UnEqualized"
  
  dec1 = Instr(1,number1,".")
  dec2 = Instr(1,number2,".")
  If dec1 <> dec2 Then equalized = "UnEqualized"

  If equalized = "UnEqualized" Then
    SetWindowText(calc_output ,"Equalize decimal first!") 
    Return 
  End If 
  
  SetWindowText(calc_output,"")

  sign1 = Left(number1,1) 
  sign2 = Left(number2,1) 
  
  lessgreater() 
  
  If ltgt = "=" Then
    outsign = "+" 
    subtractor() 
  End If 
  
  If sign1 = "-" And sign1 = "+" Then 
    If ltgt = "<" Then
      outsign = "-" 
      subtractor() 
    End If 
  End If 
  
  
  If sign1= "-" And sign2 = "+" Then
    If ltgt = ">" Then
      outsign = "+" 
      Swap number1,number2 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "+" And sign2 = "-" Then 
    If ltgt = "<" Then
      outsign = "+" 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "+" And sign2 = "-" Then
    If ltgt = ">" Then
      outsign = "-" 
      Swap number1,number2 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "-" And sign2 = "-" Then
    If ltgt = "<" Then
      outsign = "-" 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "-" And sign2 = "-" Then
    If ltgt = ">" Then
      outsign = "+" 
      Swap number1,number2 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "+" And sign2 = "+" Then
    If ltgt = "<" Then
      outsign = "+" 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "+" And sign2 = "+" Then
    If ltgt = ">" Then
      outsign = "-" 
      Swap number1,number2 
      subtractor() 
    End If 
  End If 

  SetWindowText(calc_output ,outtext) 
  outtext = ""
  number1 = ""
  number2 = ""

End Sub 
'================================================== 
Sub multiplierclick() 
  Dim sign1 As String
  Dim sign2 As String
  Dim dec1 As Ulongint
  Dim dec2 As Ulongint

  getnumbers()

  sign1 = Left(number1,1)
  Select Case sign1
    Case "-"
    Case "+"
    Case Else
        equalized = "UnEqualized"
  End Select
  
  sign2 = Left(number1,1)
  Select Case sign2
  Case "-"
  Case "+"
  Case Else
      equalized = "UnEqualized"
  End Select

  If Len(number1) <> Len(number2) Then equalized = "UnEqualized"

  dec1 = Instr(1,number1,".")
  dec2 = Instr(1,number2,".")
  If dec1 <> dec2 Then equalized = "UnEqualized"
  
  If equalized = "UnEqualized" Then
    SetWindowText(calc_output ,"Equalize decimal first!") 
    Return 
  Else
    SetWindowText(calc_output,"Multiplying!!!")
  End If 
  

  sign1 = Left(number1,1) 
  sign2 = Left(number2,1) 
  
  If sign1 <> sign2 Then
    outsign = "-" 
  End If 
  If sign1 = sign2 Then
    outsign = "+" 
  End If 
  
  multiplier() 

  SetWindowText(calc_output ,outtext) 
  outtext = ""
  number1 = ""
  number2 = ""

End Sub 
'================================================== 
Sub dividerclick() 
  Dim sign1 As String
  Dim sign2 As String
  Dim dec1 As Ulongint
  Dim dec2 As Ulongint
  
  getnumbers()

  sign1 = Left(number1,1)
  Select Case sign1
    Case "-"
    Case "+"
    Case Else
        equalized = "UnEqualized"
  End Select
  
  sign2 = Left(number1,1)
  Select Case sign2
  Case "-"
  Case "+"
  Case Else
      equalized = "UnEqualized"
  End Select
  
  If Len(number1) <> Len(number2) Then equalized = "UnEqualized"

  dec1 = Instr(1,number1,".")
  dec2 = Instr(1,number2,".")
  If dec1 <> dec2 Then equalized = "UnEqualized"

  If equalized = "UnEqualized" Then
    SetWindowText(calc_output ,"Equalize decimal first!") 
    Return 
  End If 
  
  SetWindowText(calc_output,"Dividing!!!!")

  sign1 = Left(number1,1) 
  sign2 = Left(number2,1) 
  
  If sign1 <> sign2 Then
    outsign = "-" 
  End If 
  If sign1 = sign2 Then
     outsign = "+" 
  End If 
  divider() 
  
  SetWindowText(calc_output ,outtext) 
  outtext = ""
  number1 = ""
  number2 = ""
End Sub 
'================================================== 
'================================================== 
Sub sqrtclick()
  Dim dec1 As Ulongint
  Dim dec2 As Ulongint
  Dim sign1 As String
  Dim sign2 As String

  getnumbers()

  sign1 = Left(number1,1)  
  Select Case sign1
    Case "-"
    Case "+"
    Case Else
        equalized = "UnEqualized"
  End Select
  
  sign2 = Left(number1,1)
  Select Case sign2
  Case "-"
  Case "+"
  Case Else
      equalized = "UnEqualized"
  End Select

  If Len(number1) <> Len(number2) Then equalized = "UnEqualized"

  dec1 = Instr(1,number1,".")
  dec2 = Instr(1,number2,".")
  If dec1 <> dec2 Then equalized = "UnEqualized"

  If equalized = "UnEqualized" Then
    SetWindowText(calc_output ,"Equalize decimal first!") 
    Return 
  End If 
  
  outsign = sign1
  SetWindowText(calc_output,"Extracting the square root!!")
  squareroot()

  SetWindowText(calc_output,outtext)
  outtext = ""
  number1 = ""
  number2 = ""

End Sub
'================================================== 
'================================================== 
Sub sineclick()
  Dim dec1 As Ulongint
  Dim dec2 As Ulongint
  Dim sign1 As String
  Dim sign2 As String

  getnumbers()

  sign1 = Left(number1,1)  
  Select Case sign1
    Case "-"
    Case "+"
    Case Else
        equalized = "UnEqualized"
  End Select
  
  sign2 = Left(number1,1)
  Select Case sign2
  Case "-"
  Case "+"
  Case Else
      equalized = "UnEqualized"
  End Select

  If Len(number1) <> Len(number2) Then equalized = "UnEqualized"

  dec1 = Instr(1,number1,".")
  dec2 = Instr(1,number2,".")
  If dec1 <> dec2 Then equalized = "UnEqualized"

  If equalized = "UnEqualized" Then
    SetWindowText(calc_output ,"Equalize decimal first!") 
    Return 
  End If 
  
  outsign = sign1
  SetWindowText(calc_output,"Figuring the Sine!!")
  sines()

  SetWindowText(calc_output,outtext)
  outtext = ""
  number1 = ""
  number2 = ""
End Sub
'================================================== 
'================================================== 
Sub cosineclick()
  Dim dec1 As Ulongint
  Dim dec2 As Ulongint
  Dim sign1 As String
  Dim sign2 As String

  getnumbers()

  sign1 = Left(number1,1)  
  Select Case sign1
    Case "-"
    Case "+"
    Case Else
        equalized = "UnEqualized"
  End Select
  
  sign2 = Left(number1,1)
  Select Case sign2
  Case "-"
  Case "+"
  Case Else
      equalized = "UnEqualized"
  End Select

  If Len(number1) <> Len(number2) Then equalized = "UnEqualized"

  dec1 = Instr(1,number1,".")
  dec2 = Instr(1,number2,".")
  If dec1 <> dec2 Then equalized = "UnEqualized"

  If equalized = "UnEqualized" Then
    SetWindowText(calc_output ,"Equalize decimal first!") 
    Return 
  End If 
  
  outsign = sign1
  SetWindowText(calc_output,"Figuring the CoSine!!")
  cosines()

  SetWindowText(calc_output,outtext)
  outtext = ""
  number1 = ""
  number2 = ""
End Sub
'================================================== 
'================================================== 
Sub tangentclick()
  Dim dec1 As Ulongint
  Dim dec2 As Ulongint
  Dim sign1 As String
  Dim sign2 As String

  getnumbers()

  sign1 = Left(number1,1)  
  Select Case sign1
    Case "-"
    Case "+"
    Case Else
        equalized = "UnEqualized"
  End Select
  
  sign2 = Left(number1,1)
  Select Case sign2
  Case "-"
  Case "+"
  Case Else
      equalized = "UnEqualized"
  End Select

  If Len(number1) <> Len(number2) Then equalized = "UnEqualized"

  dec1 = Instr(1,number1,".")
  dec2 = Instr(1,number2,".")
  If dec1 <> dec2 Then equalized = "UnEqualized"

  If equalized = "UnEqualized" Then
    SetWindowText(calc_output ,"Equalize decimal first!") 
    Return 
  End If 
  
  outsign = sign1
  SetWindowText(calc_output,"Figuring the Tangent!!")
  tangents()

  SetWindowText(calc_output,outtext)
  outtext = ""
  number1 = ""
  number2 = ""
End Sub
'================================================== 
'================================================== 
Sub lessgreater() 
  Dim count As Ulongint 
  Dim val1 As Integer 
  Dim val2 As Integer 

  ltgt = "=" 
  count = 2 
  While ltgt="=" And count <= Len(number1) 

    If ltgt= "=" Then
      val1 = Val(Mid(number1,count,1)) 
      val2 = Val(Mid(number2,count,1)) 
    End If 
    
    If val1 > val2 Then 
      ltgt = "<" 
      Return
    End If 
    
    If val2 > val1 Then
      ltgt = ">" 
      Return
    End If 
    
    count = count + 1 
    
  Wend 

End Sub 

'================================================== 
'================================================== 
Sub equalizer() 
  Dim sign As String 
  Dim sign1 As String 
  Dim sign2 As String 
  
  Dim int1 As String 
  Dim int2 As String 
  Dim frac1 As String 
  Dim frac2 As String 
  
  Dim length1 As Ulongint 
  Dim length2 As Ulongint 
  
  Dim dec As Ulongint 
  Dim trims As Ulongint 
  Dim count As Ulongint 
  
  If Instr(1,number1," ") <> 0 Then
    trims = 1 
  End If 
  
  If Instr(1,number2," ") <> 0 Then 
    trims = 1 
  End If 
  
  If number1 = "" Then
    number1 = "+0" 
  End If 
  
  If number2 = "" Then  
    number2 = "+0" 
  End If 
  
  sign = Left(number1,1) 
  If sign = "-" Then  
    sign1 = sign 
  Elseif sign = "+" Then
    sign1 = sign 
  Else 
    sign1 = "+" 
  End If 
  
  If sign = "+" Or sign = "-" Then 
    number1 = Mid(number1,2) 
  End If 
  
  sign = Left(number2,1) 
  If sign = "-" Then
    sign2 = sign 
  Elseif sign = "+" Then 
    sign2 = sign 
  Else 
    sign2 = "+" 
  End If 
  
  If sign = "+" Or sign = "-" Then  
    number2 = Mid(number2,2) 
  End If 
  
  dec = Instr(1,number1,".") 
  If dec = 0 Then
    int1 = number1 
    frac1 = "" 
  Else 
    int1 = Left(number1,dec-1) 
    frac1 = Mid(number1,dec+1) 
  End If 
  
  dec = Instr(1,number2,".") 
  If dec = 0 Then
    int2 = number2 
    frac2 = "" 
  Else 
    int2 = Left(number2,dec-1) 
    frac2 = Mid(number2,dec+1) 
  End If 
  
  length1 = Len(int1) 
  length2 = Len(int2) 
  
  If length1 > length2 Then 
    int2 = Space(length1 - length2) + int2
  End If 
  
  If length1 < length2 Then
    int1 = Space(length2 - length1) + int1
  End If 
  
  length1 = Len(frac1) 
  length2 = Len(frac2) 
  If length1 > length2 Then
    frac2 = frac2 + Space(length1 - length2)
  End If 
  
  If length1 < length2 Then
    frac1 = frac1 + Space(length2 - length1)
  End If 
  
  length1 = Len(int1) 
  If length1 > maxlen Then 
    int1 = Right(int1,maxlen) 
  End If 
  length1 = Len(int2) 
  If length1 > maxlen Then  
    int2 = Right(int2,maxlen) 
  End If 
  length1 = Len(frac1) 
  If length1 > maxlen Then  
    frac1 = Left(frac1,maxlen) 
  End If 
  length1 = Len(frac2) 
  If length1 > maxlen Then  
    frac2 = Left(frac2,maxlen) 
  End If 
  
  number1 = sign1 + int1 + "." + frac1 
  number2 = sign2 + int2 + "." + frac2 
  
  
  If trims = 1 Then
    sign1 = Left(number1,1) 
    number1 = Mid(number1,2) 
    number1 = Trim(number1) 
    number1 = sign1 + number1 
    
    sign2 = Left(number2,1) 
    number2 = Mid(number2,2) 
    number2 = Trim(number2) 
    number2 = sign2 + number2 

    equalized = "UnEqualized" 
    
  Else 
    equalized = "Equalized" 
  End If 

End Sub 

'================================================== 
'================================================== 
Sub adder() 
  Dim result As String 
  Dim carry As Ulongint 
  Dim dec As Ulongint 
  Dim a As Ulongint 
  Dim val1 As Ulongint 
  Dim val2 As Ulongint 
  Dim char As String *1
  
  outtext = Space(Len(number1)+1)
  carry = 0 
  dec = Instr(1,number1,".") 
  
  For a = Len(number1) To 2 Step -1 
    If a = dec Then
      Mid(outtext,a,1) = "." 
    Else 
      val1 = Val(Mid(number1,a,1)) 
      val2 = Val(Mid(number2,a,1)) 
      result = Ltrim(Str(val1 + val2 + carry)) 
      carry = 0 
      If Len(result) = 2 Then
        carry = Val(Left(result,1)) 
        char = Right(result,1)
        If char = "0" Then char = " "
      Else 
        char = result 
        If char = "0" Then char = " "
      End If 
      Mid(outtext,a,1) = char
    End If 
  Next
  outtext = trim(outtext)
  If carry >= 1 Then
    outtext = Ltrim(Str(carry)) + outtext 
  End If 
  
  For a = 1 To Len(outtext)
      If Mid(outtext,a,1) = " " Then Mid(outtext,a,1) = "0"
  Next
  If Left(outtext,1) = "." Then outtext = "0" + outtext
  
  outtext = outsign + outtext 

End Sub 
'================================================== 
'================================================== 
Sub subtractor() 
  Dim borrow As Ulongint 
  Dim dec As Ulongint 
  Dim a As Ulongint 
  Dim val1 As Ulongint 
  Dim val2 As Ulongint 
  Dim ans As String 
  
  outtext = String(Len(number1),"0")
  
  borrow = 0 
  dec = Instr(1,number1,".") 
  
  For a = Len(number1) To 2 Step -1 
    If a = dec Then
      Mid(outtext,a,1) = "." 
    Else 
      val1 = Val(Mid(number1,a,1)) 
      val2 = Val(Mid(number2,a,1)) 
      If borrow = 1 Then 
        If val1 > 0 Then
          val1 = val1 - borrow 
          borrow = 0 
          If val1 < val2 Then 
            val1 = val1 + 10 
            borrow = 1 
          End If 
        Else 
          val1 = 9 
        End If 
      Elseif borrow = 0 Then
        If val1 < val2 Then
          borrow = 1 
          val1 = val1 + 10 
        End If 
      End If 
        Mid(outtext,a,1) = Str(val1 - val2)
    End If 
    
  Next 
  outtext = Trim(outtext,"0") 
  If Left(outtext,1) = "." Then outtext = "0" + outtext 
  
  outtext = outsign + outtext 

End Sub 

'================================================== 
'================================================== 
Sub multiplier()
Dim tempstr As String

Dim string1 As String ' string are limited by signed long to 2GBytes
Dim int1 As String
Dim frac1 As String
Dim len1 As Ulongint  ' ulongint (unsigned 64 bit number)
Dim dec1 As Ulongint
Dim dec1out As Ulongint

Dim string2 As String
Dim int2 As String
Dim frac2 As String
Dim len2 As Ulongint
Dim dec2 As Ulongint
Dim dec2out As Ulongint

Dim outtxt As String
Dim outlen As Ulongint
Dim outplace As Ulongint
Dim total As Ulongint
Dim dectotal As Ulongint
Dim carry As Ulongint
Dim n1 As Integer
Dim n2 As Integer
Dim n3 As Integer
Dim n4 As Integer
Dim outp As String
Dim a As Ulongint
Dim b As Ulongint
Dim place As Ulongint

tempstr = ""
outlen    = 0
outplace  = 0
total     = 0
dectotal  = 0
carry     = 0
n1        = 0
n2        = 0
n3        = 0
n4        = 0
a         = 0
b         = 0
place     = 0

'=======================================
'   get first number
'=======================================
    string1 = Mid(number1,2)
    string1 = trim(string1)
    dec1 = Instr(string1,".")
    int1 = Left(string1,dec1-1)
    frac1 = Mid(string1,dec1+1)
    dec1 = Len(frac1)
    int1 = trim(int1)
    frac1 = trim(frac1)
    string1 = int1 + frac1
    len1 = Len(string1)
    int1 = ""
    frac1 = ""

'=======================================
'   get second number
'=======================================
    string2 = Mid(number2,2)
    string2 = trim(string2)
    dec2 = Instr(string2,".")
    int2 = Left(string2,dec2-1)
    frac2 = Mid(string2,dec2+1)
    dec2 = Len(frac2)
    int2 = trim(int2)
    frac2 = trim(frac2)
    string2 = int2 + frac2
    len2 = Len(string2)
    int2 = ""
    frac2 = ""


'=======================================
'         start double mul loop
'=======================================
    dectotal = dec1 + dec2
    outlen = len1 + len2 + 3
    place = outlen
    carry = 0
    outp = ""
    outtxt = String(outlen , "0")

    a = len2
    outplace = a
    While a >= 1
        Print a
        carry = 0
        total = 0

        n1 = Val(Mid(string2,a,1))
        
        b = len1
        While b >= 1

            n2 = Val(Mid(string1,b,1))
            
            total = Val(Mid(outtxt,place,1)) 
            
            n4 = ((n1 * n2) + carry) + total

            outp = Str(n4)

            n3 = Len(outp)
            If n3 = 1 Then
                    Mid(outtxt, place, 1) = outp
                    carry = 0
                    Goto incRement
            End If
            If n3 = 2 Then
                    Mid(outtxt, place, 1) = Right(outp,1)
                    carry = Val(Left(outp,1))
            End If
incRement:
            b = b - 1
            place = place - 1

        Wend
                           ' turn carry into a string
                           ' and overlay it at the begining
        If carry >= 1 Then
            Mid(outtxt,place,1) = Str(carry)
        End If
        outlen = outlen - 1  ' move over one in the result string
        place = outlen
        a = a - 1
    Wend
'=======================================
'   recreate strings with decimals
'=======================================
        a = Len(outtxt)
        b = a - dectotal
        tempstr = Mid(outtxt,1,b) + "." + Mid(outtxt,b+1)
        outtxt = tempstr
        tempstr = ""

    outtxt = trim(outtxt,"0")
    If Left(outtxt,1) = "." Then outtxt = "0" + outtxt
    
    outtext = outsign + outtxt

End Sub
'==================================================
'==================================================
Sub divider()
  Dim num1 As String
  Dim num2 As String
  
  Dim dec1 As Ulongint
  Dim dec2 As Ulongint
  Dim int1 As String
  Dim int2 As String
  Dim frac1 As String
  Dim frac2 As String
  
  Dim decpos1 As Ulongint
  Dim decpos2 As Ulongint
  Dim decpos3 As Ulongint
  
  Dim num(10) As String
  Dim answer As String
  Dim shortanswer As String
  
  Dim count As Ulongint
  Dim count1 As Ulongint
  Dim count2 As Ulongint
  Dim ans As String
  Dim finished As Integer
  Dim length As Longint
  Dim lengthnum1 As Ulongint
  
  Dim length1 As Ulongint
  Dim length2 As Ulongint
  
  num1 = Mid(number1,2)
  num1 = Trim(num1)
  
  num2 = Mid(number2,2)
  num2 = Trim(num2)
    
  dec1 = Instr(1,num1,".")
  dec2 = Instr(1,num2,".")
  
  If dec1 = Len(num1) Then
    int1 = Left(num1,dec1-1)
    frac1 = ""
  Else
    int1 = Left(num1,dec1 - 1)
    frac1 = Mid(num1,dec1 + 1)
  End If
    
  If dec2 = Len(num2) Then
    int2 = Left(num2,dec2-1)
    frac2 = ""
  Else
    int2 = Left(num2,dec2 - 1)
    frac2 = Mid(num2,dec2 + 1)
  End If

  If int1 = "0" Then
    int1 = ""
  End If
  If int2 = "0" Then
    int2 = ""
  End If
    
  If int1 = "" Then
    num1 = frac1
  Else
    num1 = int1 + frac1
  End If
  
  If int2 = "" Then
    num2 = frac2
  Else
    num2 = int2 + frac2
  End If
  
  If num2 = "" Then num2 = "1"

  decpos1 = Len(frac1)
  decpos2 = Len(frac2)
  decpos3 = Len(int1) + decpos2
  outtext = ""
  
  int1 = ""
  frac1 = ""
  int2 = ""
  frac2 = ""

  lengthnum1 = Len(num1)
  
  For count = 0 To 9
    number1 = num2
    number2 = Str(count)
    dividerequalizer()
    multiplier()
    num(count) = outtext
  Next
  
  answer = ""
  finished = 0
  count2 = 1
  number1 = Mid(num1,count2,1)
  Do
    count1 = 10
    Do
      count1 = count1 - 1
      number2 = num(count1)
      ans = Left(number1,1)
      If ans = " " Then ans = ""
      number1 = trim(Mid(number1,2))
      number1 = ans + number1
      dividerequalizer()
      lessgreater()
    Loop Until (ltgt = "=") Or (ltgt = "<")

    shortanswer = shortanswer + Str(count1)
    If Len(shortanswer) >= 5000 Then
        answer = answer + shortanswer
        shortanswer = ""
    End If

    length = Len(answer) + Len(shortanswer)
    length = length - decpos3

Print ,length , count1

    subtractor()

    count2 = count2 + 1
    If count2 <= lengthnum1 Then  
      ans = Mid(num1,count2,1)
    Else
      ans = "0"
    End If
    
    number1 = Left(outtext,Len(outtext)-1)
    number1 = Mid(number1,2)
    If number1 = "0" Then
      number1 = ""
    End If
    
    number1 = number1 + ans

    If outtext ="+0." Then
        If count2 > lengthnum1 Then finished = 1
    End If
    If outtext = "-0." Then
        If count2 > lengthnum1 Then finished = 1
    End If
    
    If length > maxlen Then finished = 1
    
  Loop Until finished = 1

  answer = answer + shortanswer
  shortanswer = ""
  answer = Left(answer,decpos3) + "." + Mid(answer,decpos3 + 1)

  Do
    ans = Left(answer,1)
    If ans = "0" Then
      answer = Mid(answer,2)
    End If      
  Loop Until ans <> "0"

 
  outtext = outsign + answer

End Sub
'=============================================== 
'=============================================== 
Sub dividerequalizer() 
    Dim sign1 As String*1
    Dim sign2 As String*1
    Dim num1 As String
    Dim num2 As String
    Dim length1 As Ulongint
    Dim length2 As Ulongint
    
    sign1 = Left(number1,1)
    sign2 = Left(number2,1)
    
    If sign1 = "-" Or sign1 = "+" Then 
        number1 = Mid(number1,2)
    Else 
        sign1 = "+"
        number1 = number1
    End If
    
    If sign2 = "-" Or sign2 = "+" Then 
        number2 = Mid(number2,2)
    Else 
        sign2 = "+"
        number2 = number2
    End If

    number1 = trim(number1)
    number2 = trim(number2)

    If Right(number1,1) <> "." Then number1 = number1 + "."
    If Right(number2,1) <> "." Then number2 = number2 + "."
    
    length1 = Len(number1)
    length2 = Len(number2)

    If length1 < length2 Then
        number1 = Space(length2 - length1) + number1
    End If
    
    If length1 > length2 Then
        number2 = Space(length1 - length2) + number2
    End If
    number1 = sign1 + number1
    number2 = sign2 + number2
'print number1
'print number2
'print "==========================="

End Sub
'=============================================== 
'=============================================== 
Sub squareroot() 
    Dim sign As String *1
    Dim number As String
    Dim dec As Longint
    Dim int1 As String
    Dim frac1 As String
    Dim intlen As Ulongint
    Dim fraclen As Ulongint
    Dim ans As String
    Dim answer As String
    Dim num(10) As String
    
    Dim length As Longint
    Dim lengthnum1 As Ulongint
    
    Dim finished As Longint
    
    Dim count As Ulongint
    Dim count1 As Ulongint
    Dim count2 As Ulongint
    Dim doublevalue As String
    
    sign = Left(number1,1)
    number = Mid(number1,2)
    number = trim(number)
    
    dec = Instr(1,number,".")
    int1 = Left(number,dec-1)
    frac1 = Mid(number,dec+1)
    intlen = Len(int1)
    fraclen = Len(frac1)
    
    If intlen Mod 2 = 1 Then int1 = "0" + int1
    
    dec = (Len(int1)/2)+1
    
    If fraclen Mod 2 = 1 Then frac1 = frac1 + "0"
    
    number = int1 + frac1
    
    lengthnum1 = Len(number)
    
    For count = 0 To 9
        number1 = Str(count)
        number2 = Str(count)
        dividerequalizer()
        multiplier()
        num(count) = outtext
    Next
    
    answer = ""
    finished = 0
    count2 = 1
    number1 = Mid(number,count2,2)
    Do
        count1 = 10
        Do
            count1 = count1 - 1
            number2 = num(count1)
            ans = Left(number1,1)
            If ans = " " Then ans = ""
            number1 = trim(Mid(number1,2))
            number1 = ans + number1
            dividerequalizer()
            lessgreater()
        Loop Until (ltgt = "=") Or (ltgt = "<")

        answer = answer + Str(count1)

        length = Len(answer)
        length = length - dec
    
        subtractor()

Print ,length , count1

        count2 = count2 + 2
        If count2 <= lengthnum1 Then  
            ans = Mid(number,count2,2)
        Else
            ans = "00"
        End If
    
        number1 = Left(outtext,Len(outtext)-1)
        number1 = Mid(number1,2)
        If number1 = "0" Then
            number1 = ""
        End If
    
        number1 = number1 + ans
        ans = number1
        
        If outtext ="+0." Then
            If count2 > lengthnum1 Then finished = 1
        End If
        If outtext = "-0." Then
            If count2 > lengthnum1 Then finished = 1
        End If
    
        If length > maxlen Then finished = 1
    
        number1 = answer
        number2 = "2"
        dividerequalizer()
        multiplier()
        doublevalue = Mid(outtext,2)
        doublevalue = Left(doublevalue,Len(doublevalue)-1)
        For count = 0 To 9
            number1 = doublevalue + Str(count)
            number2 = Str(count)
            dividerequalizer()
            multiplier()
            num(count) = outtext
        Next
       
        number1 = ans
        
    Loop Until finished = 1
    
    answer = Left(answer,dec-1) + "." + Mid(answer,dec)
    outtext = "+" + answer 

End Sub 
'=============================================== 
'=============================================== 
Sub sines()
    Dim As String x,mxs, term, sigma, last_sigma,divisor
    Dim As Integer n
    Dim As String sign1,sign2

    x = number1
    
    ' square x
    number1 = x
    number2 = x
    equalizer()
    sign1 = Left(number1,1)
    sign2 = Left(number2,1)
    If sign1<>sign2 Then outsign = "-" Else outsign = "+"
    multiplier()

    'set mxs to -(x*x)
    mxs = outtext
    Mid(mxs,1,1)="-"
    term = x
    sigma = x
    n = 1   ' the only freebasic integer used
    Do
        last_sigma = sigma      ' keep a copy of the last sigma
        n = n + 2               ' very fast integer math
        number1 = Str(n)
        number2 = Str(n-1)
        equalizer()
        outsign = "+"
        multiplier()
        divisor = outtext
        
        'term=term * mxs
        number1 = term
        number2 = mxs
        equalizer()
        sign1 = Left(number1,1)
        sign2 = Left(number2,1)
        If sign1<>sign2 Then outsign = "-" Else outsign = "+"
        multiplier()
        term = outtext
        
        'term=term / divisor
        number1 = term
        number2 = divisor
        equalizer()
        sign1 = Left(number1,1)
        sign2 = Left(number2,1)
        If sign1<>sign2 Then outsign = "-" Else outsign = "+"
        divider()
        term=outtext
        
        'sigma = sigma + term
        number1 = sigma
        number2 = term
        equalizer()
        trancendental_funct_analyzer()
        sigma = outtext 
        
        Print n,sigma,term   
    
    Loop Until last_sigma = sigma
    
    outtext = sigma
End Sub
'=============================================== 
'=============================================== 
Sub cosines()
    Dim As String x,mxs, term, sigma, last_sigma,divisor
    Dim As Integer n
    Dim As String sign1,sign2
    x = number1
    
    ' square x
    number1 = x
    number2 = x
    equalizer()
    outsign = "+"
    multiplier()

    'set mxs to -(x*x)
    mxs = outtext
    Mid(mxs,1,1)="-"
    
    term = "+1"
    sigma = "+1"
    n = 0  ' the only freebasic integer used
    Do
        last_sigma = sigma      ' keep a copy of the last sigma
        n = n + 2               ' very fast integer math
        number1 = Str(n)
        number2 = Str(n-1)
        equalizer()
        outsign = "+"
        multiplier()
        divisor = outtext
        
        'term=term * mxs
        number1 = term
        number2 = mxs
        equalizer()
        sign1 = Left(number1,1)
        sign2 = Left(number2,1)
        If sign1<>sign2 Then outsign = "-" Else outsign = "+"
        multiplier()
        term = outtext
        
        'term=term / divisor
        number1 = term
        number2 = divisor
        equalizer()
        sign1 = Left(number1,1)
        sign2 = Left(number2,1)
        If sign1<>sign2 Then outsign = "-" Else outsign = "+"
        divider()
        term=outtext
        
        'sigma = sigma + term
        number1 = sigma
        number2 = term
        equalizer()
        trancendental_funct_analyzer()
        sigma = outtext 
        
        Print n,sigma,term   
    
    Loop Until last_sigma = sigma
    
    outtext = sigma
End Sub
'=============================================== 
'=============================================== 
Sub tangents()
End Sub
'=============================================== 
'=============================================== 
Sub trancendental_funct_analyzer()
    Dim As String sign1,sign2
    
  sign1 = Left(number1,1) 
  sign2 = Left(number2,1) 
  
  lessgreater() 
  
  If sign1 = "+" And sign2 ="+" Then
    outsign = "+" 
    adder() 
  End If 
  
  If sign1 = "-" And sign2 ="-" Then
    outsign = "-" 
    adder() 
  End If 
  
  If sign1 = "-" And sign2 = "+" Then
    If ltgt = "=" Then
      outsign = "+" 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "+" And sign2 = "-" Then 
    If ltgt = "="  Then
      outsign = "+" 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "-" And sign2 = "+" Then 
    If ltgt = "<" Then
      outsign = "-" 
      subtractor() 
    End If 
  End If 
  If sign1 = "-" And sign2 = "+" Then 
    If ltgt = ">" Then
      outsign = "+" 
      Swap number1,number2 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "+" And sign2 = "-" Then 
    If ltgt = "<" Then
      outsign = "+" 
      subtractor() 
    End If 
  End If 
  
  If sign1 = "+" And sign2 = "-" Then
    If ltgt = ">" Then
      outsign = "-" 
      Swap number1,number2 
      subtractor() 
    End If 
  End If 
End Sub

'=============================================== 
'=============================================== 
Sub clearinput1() 
  SetWindowText(calc_input1,"") 
  equalized = "UnEqualized"
  SetWindowText(text1,equalized) 
End Sub 
'=============================================== 
'=============================================== 
Sub saveinput1() 
        getnumbers()
        file = ""
        getfilename()

        If file <> "" Then
            Open file For Output As #1
            Print #1,number1
            Close #1
        End If
End Sub 
'=============================================== 
'=============================================== 
Sub loadinput1() 
    file = ""
    getfilename()
    
    If file <> "" Then
        Open file For Input As #1
        Line Input #1 ,outtext
        SetWindowText(calc_input1,outtext)
        Close #1
        'equalizeclick()
        equalized = "UnEqualized"
        SetWindowText(text1,equalized) 
    End If

End Sub 
'=============================================== 
'=============================================== 
Sub clearinput2() 
  SetWindowText(calc_input2,"") 
  equalized = "UnEqualized"
  SetWindowText(text1,equalized) 
End Sub 
'=============================================== 
'=============================================== 
Sub saveinput2() 
        getnumbers()
        file = ""
        getfilename()

        If file <> "" Then
            Open file For Output As #1
            Print #1,number2
            Close #1
        End If
End Sub 
'=============================================== 
'=============================================== 
Sub loadinput2() 
    file = ""
    getfilename()
    
    If file <> "" Then
        Open file For Input As #1
        Line Input #1 ,outtext
        SetWindowText(calc_input2,outtext)
        Close #1
        'equalizeclick()
        equalized = "UnEqualized"
        SetWindowText(text1,equalized) 
    End If

End Sub 
'=============================================== 
'=============================================== 
Sub saveoutput() 
    Dim charcount As Ulongint
    charcount = GetWindowTextLength(calc_output) + 1
    outtext = Space(charcount)
    GetWindowText(calc_output,outtext,charcount)
  
        file = ""
        getfilename()

        If file <> "" Then
            Open file For Output As #1
            Print #1,outtext
            Close #1
        End If
    outtext = ""
End Sub 
'=============================================== 
'=============================================== 
Sub getfilename()
        Dim ofn As OPENFILENAME
        Dim filename As Zstring * MAX_PATH+1
        
        With ofn
                .lStructSize                 = sizeof( OPENFILENAME )
                .hwndOwner                        = hWnd
                .hInstance                        = GetModuleHandle( NULL )
                '.lpstrFilter                 = strptr( !"All Files, (*.*)\0*.*\0Bas Files, (*.BAS)\0*.bas\0\0" )
                .lpstrFilter                 = Strptr( !"Number Files, (*.num)\0*.num\0\0" )
                .lpstrCustomFilter         = NULL
                .nMaxCustFilter         = 0
                .nFilterIndex                 = 1
                .lpstrFile                        = @filename
                .nMaxFile                        = sizeof( filename )
                .lpstrFileTitle                = NULL
                .nMaxFileTitle                = 0
                .lpstrInitialDir        = NULL
                '.lpstrTitle                        = @"File Open Test"
                .lpstrTitle                        = @"Save File"
        .Flags                                = OFN_EXPLORER 'or OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST
                .nFileOffset                = 0
                .nFileExtension                = 0
                .lpstrDefExt                = NULL
                .lCustData                        = 0
                .lpfnHook                        = NULL
                .lpTemplateName                = NULL
        End With
        
        If( GetOpenFileName( @ofn ) = FALSE ) Then
        file = ""
        Return
        Else
        Dim ext As String
        ext = Right(filename,4)
        If ext <> ".num" Then
            filename = filename + ".num"
        End If
        file = filename
    End If

End Sub
'=============================================== 
'=============================================== 
Sub load_pi()
Dim As String pi
    pi = "+3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989"
    SetWindowText(calc_input1,pi)
End Sub
fxm
Moderator
Posts: 12016
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by fxm »

outp is a function ('outp(byval as ushort, byval as long) as long') defined in win/intrin.bi (indirectly inluded by windows.bi)

To find it, compile this:

Code: Select all

Dim outp As String
#Include "windows.bi"
srvaldez
Posts: 3340
Joined: Sep 25, 2005 21:54

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by srvaldez »

thank fxm
it didn't occur to me to look into include files
it would be great if the compiler would report where the duplicated symbol was previously defined
Julcar
Posts: 141
Joined: Oct 19, 2010 18:52
Contact:

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by Julcar »

I would like to have implemented OPEN CONS FOR BINARY, so I could be able to read binary streams from stdin without having to link against the whole CRT library, only to use fread()

Thanks
coderJeff
Site Admin
Posts: 4269
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by coderJeff »

Julcar wrote:I would like to have implemented OPEN CONS FOR BINARY, so I could be able to read binary streams from stdin without having to link against the whole CRT library, only to use fread()
The CRT will be linked anyway. fb's runtime uses CRT's file functions extensively and GET # will call fread().

The issue is with the mode (text/binary) that STDIN is opened. The CRT function '_setmode' can change the mode of a file after it is opened.
Can either extend the run time library with a new function (as demonstrated below), or the compiler adding new syntax to the OPEN function.

If you want to avoid #include "crt.bi" which would cause having all the CRT symbols in your main fbc source, then you can put the CRT specific code in a separate module.

Here's one possibility you can try right now for reading binary STDIN.

1) 'bintest.bas' - create a binary test file named 'test.bin'
compile: $ fbc bintest.bas
run: $ ./bintest

Code: Select all

print "Create 'test.bin'"

open "test.bin" for binary as #1
var s = "asdf" + chr(13,10) + "1234" + chr(13,10) + chr(4, 26) + chr(13,10) + "wxyz" + chr(13,10)
put #1,,s
print "Binary Length: " & len(s)
close #1

dim as integer count
dim as ubyte ch

print "Read 'test.bin'"

open "test.bin" for binary as #1
while not eof(1)
	get #1,,ch
	print count, ch
	count += 1
wend
close #1

print "Bytes read: " & count
2) 'filemode.bas' to hide the CRT symbols in a separate module

Code: Select all

#include once "crt.bi"
#include once "file.bi"

#include once "filemode.bi"

sub FileSetModeBinary( byval filehandle as long )
	_setmode( _fileno( cast( FILE ptr, fileattr(1, fbFileAttrHandle) ) ), _O_BINARY )
end sub

sub FileSetModeText( byval filehdnale as long )
	_setmode( _fileno( cast( FILE ptr, fileattr(1, fbFileAttrHandle) ) ), _O_TEXT )
end sub
3) 'filemode.bi' header file for the declarations to the new functions

Code: Select all

#pragma once

declare sub FileSetModeBinary( byval filehandle as long )
declare sub FileSetModeText( byval filehandle as long )
4) 'bincons.bas' - test program
compile: fbc bincons.bas filemode.bas
run: $ ./bincons < test.bin

Code: Select all

#include once "filemode.bi"

dim as ubyte ch
dim as integer count

print "Read STDIN"

open cons for input as #1
FileSetModeBinary( 1 )

while not eof(1)
	get #1,,ch
	print count, ch
	count += 1
wend

close #1

print "Bytes read: " & count

5) OUTPUT of bintest and bincons

Code: Select all

Create 'test.bin'
Binary Length: 22
Read 'test.bin'
 0            97
 1            115
 2            100
 3            102
 4            13
 5            10
 6            49
 7            50
 8            51
 9            52
 10           13
 11           10
 12           4
 13           26
 14           13
 15           10
 16           119
 17           120
 18           121
 19           122
 20           13
 21           10
Bytes read: 22
Read STDIN
 0            97
 1            115
 2            100
 3            102
 4            13
 5            10
 6            49
 7            50
 8            51
 9            52
 10           13
 11           10
 12           4
 13           26
 14           13
 15           10
 16           119
 17           120
 18           121
 19           122
 20           13
 21           10
Bytes read: 22
coderJeff
Site Admin
Posts: 4269
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by coderJeff »

adeyblue wrote:
coderJeff wrote: - 'On error goto' is seriously broken - like it needs to be fixed or removed
A basic fix for this that I thought about (that probably has more impact than I realise is):
I had some similar thoughts. At least getting error handling within the local procedure to work and deal with leaking issue later (which would mean child procedures called all participating in the same error handling (exception handling) scheme even when they do not have their own error handler).
Lost Zergling
Posts: 529
Joined: Dec 02, 2011 22:51
Location: France

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by Lost Zergling »

Yea, ErrorHandling should not be used for essentially coding purpose. I must say I subscribe 100% your proposals.
Thanks Jeff for all your efforts.
angros47
Posts: 2308
Joined: Jun 21, 2005 19:04

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by angros47 »

Speaking about GOTO, I was wondering: has anyone considered adding the computed goto? Basically, a way to get a code pointer not just from subroutines, but also from line labels.

If the line label is followed by a RETURN (and it was meant to be called with GOSUB), it could be called by invoking the pointer directly (like a subroutine), if it's meant to be reached with GOTO, a GOTO can be used to call a line pointer as well. As far as I know, GCC has such an extension over the standard C language

Or would such a thing open a Pandora box of troubles?
marcov
Posts: 3450
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by marcov »

angros47 wrote:
Or would such a thing open a Pandora box of troubles?
Yes. It would unbalance the stack if you are not very careful.
deltarho[1859]
Posts: 4243
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by deltarho[1859] »

Just a quick note.

My German friend did a fbc 1.08/gcc 9.4 WinLibs for me. 9.4 was released by gcc about three weeks ago.

The binaries for both 32-bit and 64-bit were much larger than any other toolchain that I have looked at over the years. I figured that perhaps there would be a performance boost, but this was not the case.

So, it looks like we have a gem in 9.3 SJLJ and coderJeff has picked a winner. All being well, 9.3 SJLJ may hold us in good stead for a couple of years, if not more. OK, there seems to be a few wrinkles in fbc 1.08, but they may not concern many members including me, and they may cease to be an issue in 1.08.1.
coderJeff
Site Admin
Posts: 4269
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by coderJeff »

I suspect the larger file sizes are due the exception handling scheme selected, though I haven't dug in enough to know for sure.

I have switched over my development set-up to the new mingw-w64-gcc-9.3 toolchain completely. The only thing I miss compared to the old mingw-w64 toolchain is that on windows 32-bit toolchain had 64-bit support built in and the 64-bit toolchain had 32-bit support built in, and I found it was easier to switch between 32-bit and 64-bit development much easier without fussing with the development environment much.
deltarho[1859] wrote:there seems to be a few wrinkles in fbc 1.08, but they may not concern many members including me, and they may cease to be an issue in 1.08.1.
Several of the issues are already fixed and it seems that the reports are starting to die down so I should be doing a release for 1.08.1 soon.
coderJeff
Site Admin
Posts: 4269
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by coderJeff »

coderJeff wrote:- rtlib coded in fb (revival of project started by Imortis)
I started working on this and making progress. A few changes coming that should not affect anyone:
- updates to the makefile to build libfbrt.a, libfbrtmt.a, etc
- fbc command line option '-z fbrt' to link the fbrt library instead of the usual 'fb'
- this will allow building both the c version and the fb version of the run time separately
- some updates to some crt/*.bi headers (quick fixes until some time later can give the headers a better review)
deltarho[1859]
Posts: 4243
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: FreeBASIC 1.08.1 and 1.09.0 Development

Post by deltarho[1859] »

Yours truly wrote:but they may not concern many members including me
That is because I don't write graphics programs. However, I use some written by others for test purposes and some of them are not behaving as they should with 1.08.0 but do so with 1.07.3. I shall check them out when 1.08.1 is released. I will report back in any event.
Post Reply