Menu

Problems with word add and sub

2009-08-24
2013-05-30
  • Edward LaBudde

    Edward LaBudde - 2009-08-24

    Hi all newbie here ran into another problem with the new release (0.9 12/8/2009)

    I have a vector math problem:

    Dim Vector_sum as word

    Vr = 100
    Vi = 49

    Vector_sum = Vr*Vr+Vi*Vi, This does not work as Vector_sum = 113 not 12401

    Vector_sum = Vr*Vr - Vi*Vi, This does not work as Vector_sum = 65455 not 7599

    Vector_sum = Vr*Vr works Vector_sum = 10000

    Vector_sum = Vr*Vr*2, This does not work as Vector_sum = 32 not 20000

    The earlier release (0.9 24/1/2009) has the same problem

    What is going on?

    Regards, Ed.

     
    • Nobody/Anonymous

      I think you should declare Vr and Vi as word or force the operation to word.

       
    • Edward LaBudde

      Edward LaBudde - 2009-08-25

      Nobody, thanks for the tip.  It seems to work ok now.  This also works:
      Vector_sum = [word]Vr*Vr+[word]Vi*Vi. 
      I do not understand why this is necessary, as Vr and Vi will be a Byte variable.  Can someone please explain why this is necessary.  Thanks, Ed.

       
    • Nobody/Anonymous

      GCBasic does not use word calculations, unless you specify it, or the inputs are words.  The fact that is points to a word, does not trigger word math functions.  This allows for more control on the operations and the savings of program code over assuming everything needs 16 bit math.

       

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.