Menu

Math division and multiplication

Help
Jonny!!!
2009-03-07
2013-05-30
  • Jonny!!!

    Jonny!!! - 2009-03-07

    Is it possible to do division and multiplication with irrational numbers in GCBASIC? Is there any limitations?

    e.g. 12/3.1416

     
    • vitesse1508

      vitesse1508 - 2009-03-14

      Sorry to instrude on your thread but since this was also a question of the same nature, I also wish to know this as Im trying to do a caculation on value from AN0 such as:

      DataConstant = (5 / 255)
      Reading = ReadAD(AN0)

      Voltage = Reading * DataConstant

         CLS
           PRINT "Voltage: "
           LOCATE 1,2
           LCDInt(Voltage)

      Obviously this needs rounding up somehow

       
      • Hugh Considine

        Hugh Considine - 2009-03-15

        Try something like this:

        Voltage = [word]ReadAD(AN0) * DataConstant

        The [word] forces GCBASIC to treat ReadAD as a word variable, which will result in the word routines being used for the calculation.

         
    • Nobody/Anonymous

      GCBASIC can only deal with whole numbers at the moment. The best workaround for this is to multiply everything by 1000, so 12000/3142.

       
    • kent_twt4

      kent_twt4 - 2009-03-15

      Also, using a precision voltage reference IC has been discussed before on this forum.  In short, if a 4.096V reference IC output is applied to the Vref+ pin, and say a word sized a-d input is used (e.g. ReadAD10(AN0)), an integer multiplier is obtained.  Your volts per bit is then, 4.096V/1024bits or an even 4, which makes for easy scaling.  Probably not necessary for every project you have, but handy when needed.

       

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.