Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/16/01 07:36
Read: times


 
#17697 - RE: Multiplication 2 bytes by 0.034146
Arnon,

Here is a way you can multiply the equivalent of 0.034145355224609375 times whatever number. If the number you are multiplying by is over 0x3fff, you will overrun the accumulator. If you don't need as much accuracy, you can change the shiftFactor to 16, and things get easier in assembly by just using the upper 16 bits of the multiplication result.

<>< Lance.

typedef unsigned int uint16;
typedef unsigned long uint32;
int shiftFactor = 18;
uint32 MagicConstant = 8951; // .034146 * (1 << BitShift)


uint16 MultiplyBy0_034146( uint16 value )
{
// This will round the result.
return ( (uint32)value * MagicConstant + (1<<(shiftFactor-1))) >> shiftFactor;
}


List of 16 messages in thread
TopicAuthorDate
Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication - Lance            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      
RE: Multiplication 2 bytes by 0.034146            01/01/70 00:00      

Back to Subject List