Menu

Single variables

jackjames
2025-05-06
2025-05-08
  • jackjames

    jackjames - 2025-05-06

    I am trying to convert some programs that I had written in MikroBasic to GCBasic to be able to use new processors not supported by the old MikroBasic.
    Until some time ago it was not possible because of floating point calculations, now that the good Evan has greatly improved the compiler this problem no longer exists.
    So I have some questions:
    I have to dimension an array of singles and I have to store three values in it.
    I did this:
    Dim EXTRA_BASS_COEFF_A (2) As Single
    EXTRA_BASS_COEFF_A (0) = 1.0
    EXTRA_BASS_COEFF_A (1) = -1.561
    EXTRA_BASS_COEFF_A (2) = 0.6414
    I know that the compiler uses the index 0 to store the size of the array, so is it feasible?
    Then, This instruction gives me an error, it says it can't store the negative value:
    EXTRA_BASS_COEFF_A = 1.0, -1.561, 0.6414

     
  • Anobium

    Anobium - 2025-05-06

    Looks to me like the array load function does not work. Well.. I never test because I never implemented that load function and I did not write a function to prevent use. Actually, I never even thought about this load function.

    EXTRA_BASS_COEFF_A = 1.0, -1.561, 0.6414 will not work.


    The use of array element zero. I can only use empirical testing to assess this element.

    The following program shows that element 0 is not maintained therefore single array permit usage of element 0. However, therefore element 0 does not return the number array element.

    Please do test and evaluate. Share your insights.

    Evan

    #chip 16f886
    #option Explicit
    
    Dim arrayAddress as Byte
    
    Dim EXTRA_BASS_COEFF_A (2) As Single
    EXTRA_BASS_COEFF_A (1) = 1.0
    EXTRA_BASS_COEFF_A (2) = -1.561
    EXTRA_BASS_COEFF_A (3) = 0.6414
    
    
    // EXTRA_BASS_COEFF_A = 1.0, -1.561, 0.6414
    
    #DEFINE USART_BAUD_RATE 9600
    #DEFINE USART_TX_BLOCKING
    #DEFINE USART_DELAY OFF
    
    arrayAddress = 1
    EXTRA_BASS_COEFF_A (arrayAddress) = EXTRA_BASS_COEFF_A (arrayAddress) * 2
    
    HSerPrint SingleToString(  EXTRA_BASS_COEFF_A (arrayAddress) )
    HserPrintCRLF
    HSerPrint SingleToString (EXTRA_BASS_COEFF_A (0))
    HserPrintCRLF
    HSerPrint EXTRA_BASS_COEFF_A (0)
    HserPrintCRLF
    HserPrint "end"
    
     
    • jackjames

      jackjames - 2025-05-06

      I have run some tests with your program with some modifications and picsimlab.
      The value of the array at address 0 can be used to read and write data.
      The values are displayed correctly albeit with some rounding.
      However, I noticed a problem, I do not know if it is due to the compiler or the simulator.
      On the first line of printing on the serial (HSerPrint "0:") on the terminal a dot "." is displayed before the data to be printed.
      I attach an image with the result.

      List:

          #Chip 16f886
          #Option Explicit
      
          Dim ArrayAddress As Byte
      
          Dim EXTRA_BASS_COEFF_A (3) As Single
          EXTRA_BASS_COEFF_A (0) = 201.034
          EXTRA_BASS_COEFF_A (1) = 1.01234
          EXTRA_BASS_COEFF_A (2) = -1.561
          EXTRA_BASS_COEFF_A (3) = 0.6414
      

      // EXTRA_BASS_COEFF_A = 1.0, -1.561, 0.6414

          #Define USART_BAUD_RATE 9600
          #Define USART_TX_BLOCKING
          #Define USART_DELAY Off
      
          ArrayAddress = 1
          EXTRA_BASS_COEFF_A (ArrayAddress) = EXTRA_BASS_COEFF_A (ArrayAddress) * 2
      
          HSerPrint "0:"
          HSerPrint SingleToString (EXTRA_BASS_COEFF_A (0))
          HSerPrintCrLf
      
          HSerPrint "1: (2 * ValArray)"
          HSerPrint SingleToString (EXTRA_BASS_COEFF_A (ArrayAddress))
          HSerPrintCrLf
      
          HSerPrint "2:"
          HSerPrint SingleToString (EXTRA_BASS_COEFF_A (2))
          HSerPrintCrLf
      
          HSerPrint "3:"
          HSerPrint SingleToString (EXTRA_BASS_COEFF_A (3))
          HSerPrintCrLf
          HSerPrint "end"
      
       

      Last edit: jackjames 2025-05-06
  • Anobium

    Anobium - 2025-05-07

    Great.

    The '.' I will ignore.

    The rounding is the outcome of conversation to string. Check the hex values, by using StringToHex() and then use an online IEEE converter. All should look OK.

     
  • Anobium

    Anobium - 2025-05-08

    🚀 GCBASIC Compiler Update: Fixing Array Assignment Issue

    Non-BYTE arrays were failing on shorthand assignments—@Jackjames spotted it, and I fixed it!

    🛠️ A quick check now ensures proper error handling, making GCBASIC more stable and reliable. ✅

    Curious how I found the issue? Read the full post—it took 2.5 hours to track down, 5 seconds to fix! ⏳😅

    Read the full KO-FI post here

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.