Re: I am experiencing a major math error
Re: I am experiencing a major math error
- Subject: Re: I am experiencing a major math error
- From: Mike Paquette <email@hidden>
- Date: Mon, 15 Nov 2004 11:46:40 -0800
On Mon, 15 Nov 2004 12:08:53 -0700, April Gendill
<email@hidden> wrote:
Ok, I am trying to multiply one number by another an the answer is like
700,000,000 off.
so I have
long number1 = 2295104;
long number2 = 2048;
long number 3 = number1 * number2;
NSLog gives me: 405405696
well that is totaly wrong. In the calculator the correct answer is:
4700372992
A long is a 32 bit quantity in the current ABI. Your math operation
requires 33 bits to represent it's result, so as a result you have a
numerical overflow.
Try using the ANSI int64_t type, which will hold up to 64 bits. Don't
forget to #include <stdint.h>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden