Proton BASIC Compiler - Maximum, Minimum and Square Root Routines


  • PicŪ Basic


  • Maximum, Minimum and Square Root Routines

    I would like to share some of work around with everyone especially the MAXimum and MINinimum keywords that were removed from the compiler as a result of upgrades and also square root routines.

    you can copy the codes in part or include as a whole anyway you want. I have it in an include file called maths.inc so i just include the file then I make a call to any function i want.

    Code:
    GoTo Over_Define
    
    $define GetMAxMin(BufferSize, Buffer, MaxVal,MinVal) MaxVal = Buffer[0]'
                                                         MinVal = Buffer[0]'
                                                         For MacIndex = 0 To (BufferSize - 1)'
                                                         If Buffer[MacIndex] > MaxVal Then'
                                                         MaxVal = Buffer[MacIndex]'
                                                         ElseIf Buffer[MacIndex] < MinVal Then'
                                                         MinVal = Buffer[MacIndex]'
                                                         EndIf'
                                                         Next
    
    
    
    
    $define GetMax (BufferSize, Buffer, MaxVal) MaxVal = Buffer[0]'
                                                For MacIndex = 0 To (BufferSize - 1)'
                                                    If Buffer[MacIndex] > MaxVal Then'
                                                       MaxVal = Buffer[MacIndex]'
                                                    EndIf'
                                                Next
    
    
    
    
    $define GetMin (BufferSize, Buffer, MinVal) MinVal = Buffer[0]'
                                                For MacIndex = 0 To (BufferSize - 1)  '
                                                    If Buffer[MacIndex] < MinVal Then'
                                                       MinVal = Buffer[MacIndex]'
                                                    EndIf'
                                                Next
    
    
    
    
    $define SquareRootFunct(Snumber,Sqroot) Square = 1'
                                            Delta = 3  '
                                            While Square <= Snumber'
                                            Square = Square + Delta'
                                            Delta = Delta + 2      '
                                            Wend                    '
                                            Sqroot = (Delta/2 ) - 1
    
    
    
    
    Over_Define:
    Okay, firstly all the variables needs to be declared to specific type you want, have only tried to use Byte and word type variable, I have not used Floating type and Dword in the Square Root function.


    Maximum and Minimum


    Buffersize is the size of your array, which you can declare as a variable or a constant. e.g


    Dim Buffersize as byte = 128 or
    symbol Buffersize = 128


    Buffer is the name of the array. e.g Dim MyArray[Buffersize] as byte


    MaxVal is the maximum value in the array


    MinValue is the minimum value in the array


    Example of calling the function.


    GetMaxMin (Mybuffersize, Mybuffer, Maxvalue, MinValue)


    And for the Square Root Function same procedure, declare your variables appropriately, then call the function




    SquareRootFunct (Mynumber, Myresult)


    Snumber is the number you re finding the square root.


    Sqroot is the result that will be returned


    Hope this Help someone


    Tunde
  • Recent Activity

    top204-15

    The Proton manual

    Thread Starter: towlerg

    I don't know if it's just me but I don't seem to be able to paste examples from the PDF. I'm sure I could at some time in the past but maybe I'm...

    top204 Today, 12:55 Go to last post
    top204-15

    SD File System revisited

    Thread Starter: AlbertoFS

    I have reviewed the SD_File_System in a file.inc only checking all macros using the preprocessor too. I have tried to make the commands easier to...

    top204 Today, 13:14 Go to last post