Pelican Parts Forums

Pelican Parts Forums (http://forums.pelicanparts.com/)
-   Off Topic Discussions (http://forums.pelicanparts.com/off-topic-discussions/)
-   -   programmers - very large numbers and c++ (http://forums.pelicanparts.com/off-topic-discussions/569552-programmers-very-large-numbers-c.html)

id10t 10-13-2010 07:51 AM

programmers - very large numbers and c++
 
Anyone have a link to a library, etc. for working with very large numbers? Think squaring a 32 bit number, square rooting a 64 bit number, etc.

Can work with MS/Visual Studio or preferably with GCC/G++

Thanks!

BlueSkyJaunte 10-13-2010 07:57 AM

Like GMP? The GNU MP Bignum Library

Rob Channell 10-13-2010 06:37 PM

The 32 bit Microsoft Visual Studio compilers can do floats or doubles right out of the box. Floats are 32 bit and the doubles are 64 bit. 64 bit seems to be enough precision for most calculations. The max value for a 32 bit float is 3.4*10e38 and the max value for a double is 1.7*10e308. How big of a number do you need?

Other libraries are geared toward very large numbers such as used in computing pi to 1 billion digits or prime number searches, etc. I think some of these libraries are referred to as arbitrary precision libraries because you can choose how many digits of precision the library will provide. It all costs in terms of memory and speed.

If you are currently using float type variables in the C/C++ code then try changing them to a double and see if you get the response you would like. don't forget to take into account the change in size of any data structures using these types. It can mess you up with pointers and such depending on how the current code is written to access the data structures.

DavidB911 10-13-2010 11:46 PM

We were always told to convert it to a number between 0 and 10. Then you can multiply the number of decimals needed. Say if its "1234" being squared it would be:

(1234)^2 = 1522756

Divide 1234 by 1000, then square 1.234. Multiply the answer by 1e6 to get 1522756.

red-beard 10-14-2010 04:27 AM

Quote:

Originally Posted by DavidB911 (Post 5614575)
We were always told to convert it to a number between 0 and 10. Then you can multiply the number of decimals needed. Say if its "1234" being squared it would be:

(1234)^2 = 1522756

Divide 1234 by 1000, then square 1.234. Multiply the answer by 1e6 to get 1522756.

You get serious rounding errors that way. That works in engineering, but it won't work in banking software.

A lot the answer depends on the use.

id10t 10-14-2010 04:45 AM

What is happening is...

A math instructor wants to offer a class based on working with number theory. Programming needed, but the math kids aren't programmers (neither is he, although he admits to some turbo pascal 25 years ago). So I hooked him up with a programming instructor who teaches basic C/C++. Match made in heaven - he gets his math stuff done, she gets projects for her students and the students get experience working with a "customer".

I get happy too, 'cause I'm building them a custom dev environment in Linux if it can't be done in VS.

The GMP library seems to work for a few tests, but I need to write a bit more code for more testing.

red-beard 10-14-2010 06:04 AM

OK, then as I thought the decimal point solution (engineering notation) won't work.

You need basically and integer*128 or *256 or more.

This might be a good assignment, because it can show the students the limitations of the computer and how computers really generate numbers.


All times are GMT -8. The time now is 05:01 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0
Copyright 2025 Pelican Parts, LLC - Posts may be archived for display on the Pelican Parts Website


DTO Garage Plus vBulletin Plugins by Drive Thru Online, Inc.