addition long values to long double value ? 
Author Message
 addition long values to long double value ?

hi,

i want to add long values.
e.g.
longvalue_sum += longvalue_n;

but the sum of this values overflows.
therefor i must take a "long double" value. in this case c-compiler needs
floating-lib.
and the execution takes a long time.

is there an another possibility to do this ?

thanks in advance..



Mon, 04 Jul 2005 19:41:11 GMT  
 addition long values to long double value ?
in comp.lang.c i read:

Quote:
>i want to add long values.
>e.g.
>longvalue_sum += longvalue_n;

>but the sum of this values overflows.

which has implementation defined behavior, and is allowed to raise a
signal.

if there are never negative values use unsigned long.

Quote:
>therefor i must take a "long double" value. in this case c-compiler needs
>floating-lib.  and the execution takes a long time.

>is there an another possibility to do this ?

does your implementation support `long long'?  (or unsigned long long if
possible.)

if not and you want to continue to use integers then you'll need to scale
the values yourself, which means another variable and the use of functions
where you currently use operators.

--
bringing you boring signatures for 17 years



Mon, 04 Jul 2005 20:30:35 GMT  
 addition long values to long double value ?

Quote:

> in comp.lang.c i read:

> >i want to add long values.
> >e.g.
> >longvalue_sum += longvalue_n;

> >but the sum of this values overflows.

> which has implementation defined behavior, and is allowed to raise a
> signal.

N869
3.  Terms and definitions
3.18
       [#3]  EXAMPLE  An  example  of  undefined  behavior  is  the
       behavior on integer overflow.

--
pete



Mon, 04 Jul 2005 21:15:39 GMT  
 addition long values to long double value ?

Quote:

> hi,

> i want to add long values.
> e.g.
> longvalue_sum += longvalue_n;

> but the sum of this values overflows.
> therefor i must take a "long double" value. in this case c-compiler needs
> floating-lib.
> and the execution takes a long time.

> is there an another possibility to do this ?

Using floating point numbers has a lot of other potential problems you
might not be aware of. There are big number libraries available. I would
recommend using your favourite search engine to find "big number C
library" or something similar.

If you cannot find what you are looking for in a 3rd party library you
would have to create your own library.

Other options: use unsigned long if you don't need the negative or see if
sizeof(long long) > sizeof(long). If it is use that. If it is not look
into a different compiler that does support a large long long data type.

Finally, go OS or compiler specific. Maybe someone in an OS or compiler
specific newsgroup has a non-portable solution.

---

"iqgbgxmdbjlgdv.lksrqek.n";char *strchr(const char *,int); while
(*i){j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);}return 0;}



Tue, 05 Jul 2005 06:54:14 GMT  
 addition long values to long double value ?

Quote:

> > hi,

> > i want to add long values.
> > e.g.
> > longvalue_sum += longvalue_n;

> > but the sum of this values overflows.
> > therefor i must take a "long double" value. in this case c-compiler
needs
> > floating-lib.
> > and the execution takes a long time.

> > is there an another possibility to do this ?

> Using floating point numbers has a lot of other potential problems you
> might not be aware of. There are big number libraries available. I would
> recommend using your favourite search engine to find "big number C
> library" or something similar.

> If you cannot find what you are looking for in a 3rd party library you
> would have to create your own library.

> Other options: use unsigned long if you don't need the negative or see if
> sizeof(long long) > sizeof(long). If it is use that. If it is not look
> into a different compiler that does support a large long long data type.

> Finally, go OS or compiler specific. Maybe someone in an OS or compiler
> specific newsgroup has a non-portable solution.

I am guessing that long double will be a lot faster than that, and just as
accurate (as long as the total is less than 17 digits or so).
--
C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
 "The C-FAQ Book" ISBN 0-201-84519-9
C.A.P. FAQ: ftp://cap.connx.com/pub/Chess%20Analysis%20Project%20FAQ.htm


Tue, 05 Jul 2005 14:29:44 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Long long and long double

2. char size (was long long long long long int)

3. long long long long integers

4. long long integer and double precision number

5. short/long/long long Formatting questions

6. How to assign a value to unsigned long variable

7. Using values of one array as pointer counters to access data in another ( long )

8. using if..else w/ string values... (LONG)

9. Converting LONG value to CHAR array

10. C and long values.

11. long values

12. fprintf, using unsigned long values

 

 
Powered by phpBB® Forum Software