Signed integer math

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Signed integer math

Jason Plum
For the group,

Is there anyone that can give me a hand understanding how I might do signed integer math w/ haxe? (has to do with encodings/encryption)

I would really*  like to figure out this tid bit so I can port an existing application.

TYIA

--
Maximus*
WarheadsSE
MaxSource

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Signed integer math

Ian Liu Rodrigues
Maybe I did not understood your question, but every arithimetical operation is signed.
 
You can choose between integer or float calculation, although division always returns float
 
trace(5-2); // traces 3
trace(3/2); // traces 1.5
 
Cheers,
Ian Liu.
On Tue, Sep 22, 2009 at 1:35 PM, Jason Plum <[hidden email]> wrote:
For the group,

Is there anyone that can give me a hand understanding how I might do signed integer math w/ haxe? (has to do with encodings/encryption)

I would really*  like to figure out this tid bit so I can port an existing application.

TYIA

--
Maximus*
WarheadsSE
MaxSource

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Signed integer math

Jason Plum
Ok, I have certain operations that would hit the upper limit of the signed integer value, crossing over into a negative, and thus I have my problem. 

I have to make use of an older but speedy little algorithm, and it sits on top of a %32767 and a fixed 1-byte char. Any passing of the upper limits = whacked out non-functionality.


On Tue, Sep 22, 2009 at 3:51 PM, Ian Liu <[hidden email]> wrote:
Maybe I did not understood your question, but every arithimetical operation is signed.
 
You can choose between integer or float calculation, although division always returns float
 
trace(5-2); // traces 3
trace(3/2); // traces 1.5
 
Cheers,
Ian Liu.
On Tue, Sep 22, 2009 at 1:35 PM, Jason Plum <[hidden email]> wrote:
For the group,

Is there anyone that can give me a hand understanding how I might do signed integer math w/ haxe? (has to do with encodings/encryption)

I would really*  like to figure out this tid bit so I can port an existing application.

TYIA

--
Maximus*
WarheadsSE
MaxSource

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Maximus*
WarheadsSE
MaxSource

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Signed integer math

edA-qa mort-ora-y
In reply to this post by Jason Plum
Jason Plum wrote:
> Is there anyone that can give me a hand understanding how I might do
> signed integer math w/ haxe? (has to do with encodings/encryption)

Signed or unsigned you have a 32-bit limit.  Perhaps you are simply
looking to do unsigned operations in which case you can use the UInt class.

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
        http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
        http://wiki.disemia.com/HaXe
       
A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org

signature.asc (260 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Signed integer math

Jason Plum
Yes, I do hit the 32bit limit, but it is how it handles the sign that I am having one of the issues with.

Yes, I am looking at that, and I would love to use the UInt class, however it's not available for all targets.


On Tue, Sep 22, 2009 at 4:10 PM, edA-qa mort-ora-y <[hidden email]> wrote:
Jason Plum wrote:
> Is there anyone that can give me a hand understanding how I might do
> signed integer math w/ haxe? (has to do with encodings/encryption)

Signed or unsigned you have a 32-bit limit.  Perhaps you are simply
looking to do unsigned operations in which case you can use the UInt class.

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
       http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
       http://wiki.disemia.com/HaXe

A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org



--
Maximus*
WarheadsSE
MaxSource

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Signed integer math

Ian Liu Rodrigues
If you need more than 32bits representation, than a BigNum class is necessary. I guess someone already implemented that, maybe on caffeine-hx?
 
Ian Liu.

On Tue, Sep 22, 2009 at 5:18 PM, Jason Plum <[hidden email]> wrote:
Yes, I do hit the 32bit limit, but it is how it handles the sign that I am having one of the issues with.

Yes, I am looking at that, and I would love to use the UInt class, however it's not available for all targets.


On Tue, Sep 22, 2009 at 4:10 PM, edA-qa mort-ora-y <[hidden email]> wrote:
Jason Plum wrote:
> Is there anyone that can give me a hand understanding how I might do
> signed integer math w/ haxe? (has to do with encodings/encryption)

Signed or unsigned you have a 32-bit limit.  Perhaps you are simply
looking to do unsigned operations in which case you can use the UInt class.

--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
       http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
       http://wiki.disemia.com/HaXe

A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org



--
Maximus*
WarheadsSE
MaxSource

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Signed integer math

edA-qa mort-ora-y
In reply to this post by Jason Plum
Jason Plum wrote:
> Yes, I am looking at that, and I would love to use the UInt class,
> however it's not available for all targets.

Oopos, I meant Int32. I think that is supported everywhere.

You should be fined with most signed operations though multiplication is
a problem.  If multiplication is your only problem then here is the code
you need:

/**
 * Public only for test cases
 * Ref: http://www.cs.uaf.edu/~cs301/notes/Chapter5/node5.html
 */
public function uintMul( a : Int32, b : Int32 )
{
        //FEATURE: could we probably just use normal ints after this initial
transformation?
        var A = Int32.ushr( a, 16 );
        var B = Int32.and( a, Int32.ofInt( 0xffff ) );
        var C = Int32.ushr( b, 16 );
        var D = Int32.and( b, Int32.ofInt( 0xffff ) );
               
        var BD = Int32.mul( B, D );
        var AD = Int32.mul( A, D );
        var CB = Int32.mul( C, B );
        //we have no place to store the AC so we don't calculate that part
               
        var hi = Int32.add( Int32.add( Int32.ushr( BD, 16 ), AD ), CB );
        var lo = Int32.and( BD, Int32.ofInt( 0xffff ) );
       
        return Int32.add( lo, Int32.shl( hi, 16 ) );
}


--
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

BigTPoker uses haXe and DHLIB
        http://BigTPoker.com/?source=haxe-list

The dis-Emi-A haXe Library
        http://wiki.disemia.com/HaXe
       
A full set of tools, classes, and support facilities aimed at
simplifying and expediting game creation in Flash 9.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.


--
haXe - an open source web programming language
http://haxe.org

signature.asc (260 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Signed integer math

Nicolas Cannasse
In reply to this post by Jason Plum
Jason Plum a écrit :
> For the group,
>
> Is there anyone that can give me a hand understanding how I might do
> signed integer math w/ haxe? (has to do with encodings/encryption)
>
> I would really*  like to figure out this tid bit so I can port an
> existing application.

If i remember correctly, the only differences between signed and
unsigned integers are :
- display : either show a minus or a big number
- right bit shifting : >> doesn't shift the sign bit but >>> will
- comparison : > and < doesn't behave the same (you'll have to do bit
shifting to compare in unsigned mode in haXe)

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Signed integer math

Jason Plum
Thank you both!

It will take me a day or two to get this all sorted out , and I do apologize for inadvertantly saying signed instead of unsigned originally.

The Int32 class is indeed handled everywhere, and that example will likely help me sort things out. This ones going to be "fun" :)



Jason


--
haXe - an open source web programming language
http://haxe.org