home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   sci.math.symbolic      Symbolic algebra discussion      10,432 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 9,832 of 10,432   
   jacob navia to All   
   Catching overflow   
   01 Mar 18 19:55:37   
   
   From: jacob@jacob.remcomp.fr   
      
   I would like to know when a multiplication can overflow 128 bit integers.   
      
   So, I want to know if   
      
   	A x B >= pow(2,128)   
      
   If I take the logarithms (base 2) of both sides that gives:   
            log(A) + log(B) >= 128   
      
   Suppose I have a "bsr" function that gives me the position of the   
   highest set bit in a 128 bit word. That function is equivalent to   
   	ceil(log(N)) (base 2)   
   and in most machines is just one instruction (at least x86-64 or ARM64   
   have an equivalent instruction).   
      
   So my test should be:   
      
        if (bsr(A) + bsr(B) >= 128)   
             break; // avoid overflow   
      
   Does this sound correct to the math specialists here?   
      
   Sorry but I am a data processing professional, not a mathematician, so I   
   have no proof of the test above.   
      
   Thanks in advance for any help.   
      
   jacob   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca