1. math question

I was wondering if any body knows of a good way to return the lower dword
of an atom. ie. I'm useing atom's in my calculations because integers are
too small but after computing I only need to cary on with the lower dword

I'd like to chop off the high dword and cast the low dword to an integer.
p.s.  similar to an assembly's "mul ebx" where I'd use eax and ignor edx.

new topic     » topic index » view message » categorize

2. Re: math question

Hayden McKay wrote:
> 
> I was wondering if any body knows of a good way to return the lower dword
> of an atom. ie. I'm useing atom's in my calculations because integers are
> too small but after computing I only need to cary on with the lower dword
> 
> I'd like to chop off the high dword and cast the low dword to an integer.
> p.s.  similar to an assembly's "mul ebx" where I'd use eax and ignor edx.

Here is some working code. I assume both your initial inputs fit into dwords:

constant P2_16=power(2,16),
         P2_16_1=P2_16-1,
         P2_32_1=power(2,32)-1

function lo_dword_of_product(atom a1,atom a2)
-- slice a1 and a2 into words, then do the multiplies and 
-- stitch the whole thing up together.
-- Uncomment commented code lines to get the full 64-bit result.

atom result, temp
--atom result_hi_dword
integer w1_1,w1_2,w2_1,w2_2

-- unpack a1 and a2

w1_1=and_bits(a1,P2_16_1)  -- low word of a1
w2_1=and_bits(a2,P2_16_1)
w1_2=floor(a1/P2_16)       -- high word of a1
w2_2=floor(a2/P2_16)

--perform word multiplications

result=w1_1*w2_1
temp=w1_2*w2_1+w1_1*w2_2
--result_hi_dword=w1_2*w2_2

-- Now temp is a 33-bit integer, slice it to get result (and optionally hi
dword)

--result_hi_dword+=floor(temp/P2_16)
result+=and_bits(temp*P2_16,P2_32_1)  -- intermediate result has 49 bits, so 
                                      -- no digit is lost.

-- result has 33 bits now, slash that extra bit out and optionally add carry 
-- to high dword

--result_hi_dword+=(result>P2_32_1)
return and_bits(result,P2_32_1)
-- or alternatively:
--return {and_bits(result,P2_32_1),result_hi_dword}


HTH

CChris

new topic     » goto parent     » topic index » view message » categorize

3. Re: math question

Hayden McKay wrote:
> 
> I was wondering if any body knows of a good way to return the lower dword
> of an atom. ie. I'm useing atom's in my calculations because integers are
> too small but after computing I only need to cary on with the lower dword
> 
> I'd like to chop off the high dword and cast the low dword to an integer.
> p.s.  similar to an assembly's "mul ebx" where I'd use eax and ignor edx.

The easiest (and probably fastest) way is to use and_bits():
a = and_bits( a, #FFFF )

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

4. Re: math question

>From: Matt Lewis <guest at RapidEuphoria.com>
>Reply-To: EUforum at topica.com
>To: EUforum at topica.com
>Subject: Re: math question
>Date: Wed, 02 Nov 2005 04:04:19 -0800
>
>posted by: Matt Lewis <matthewwalkerlewis at gmail.com>
>
>Hayden McKay wrote:
> >
> > I was wondering if any body knows of a good way to return the lower 
>dword
> > of an atom. ie. I'm useing atom's in my calculations because integers 
>are
> > too small but after computing I only need to cary on with the lower 
>dword
> >
> > I'd like to chop off the high dword and cast the low dword to an 
>integer.
> > p.s.  similar to an assembly's "mul ebx" where I'd use eax and ignor 
>edx.
>
>The easiest (and probably fastest) way is to use and_bits():
>}}}
<eucode>
>     a = and_bits( a, #FFFF )
></eucode>
{{{


Dwords are 32-bits, so that would be
a = and_bits(a, #FFFFFFFF)


>Matt Lewis
>

~[ WingZone ]~
http://wingzone.tripod.com/

new topic     » goto parent     » topic index » view message » categorize

5. Re: math question

An easy way to extract the low DWORD from an atom is to use the remainder()
function as in a = remainder(a, #100000000). Bitwise functions such as and_bits()
are restricted to numbers #FFFFFFFF or less for both parameters so can not be
used for this purpose. A potential problem is that remainder() will return a
fractional part if the original number is not an integer. The use of floor() or a
rounding function may be necessary if this is a possibility.

Larry Miller

new topic     » goto parent     » topic index » view message » categorize

6. Re: math question

Thanks for your input CCris. I've only just got arround to reading your
reply and thank you for your code. 

Matt...
and_bits() is limited to integers so it's not posible to do }}}
<eucode>
i = and_bits(a,#7FFFFFFF) </eucode>
{{{
 wich would have worked nicley.

new topic     » goto parent     » topic index » view message » categorize

7. Re: math question

The previous response was posted prematurly.. I did'nt see some of the other
replys so I like to express thanks to larry as well. sorry about extra post.

Hayden McKay wrote:
> 
> Thanks for your input CCris. I've only just got arround to reading your
> reply and thank you for your code. 
> 
> Matt...
> and_bits() is limited to integers so it's not posible to do }}}
<eucode>
> i = and_bits(a,#7FFFFFFF) </eucode>
{{{
 wich would have worked nicley.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu