446,206 Members | 1,035 Online
Need help? Post your question and get tips & solutions from a community of 446,206 IT Pros & Developers. It's quick & easy.

# how to calculate value of pi

 P: n/a Hi, I'm pretty new to the programming world. I got stuck in the following problem. Please guide me about it. Well I'm trying to get the value of (128^100)^2 I've used long double type but to no avail. I even can't get the value of 2^128. How this problem can be solved? Similarly, I was trying to develoop a program in hich we can calculate the value of PI to our desired decimal point, but i got stuck in it. How these sort of problems can be solved in C? What tools C provides us to calculate such values? Jul 14 '07 #1
11 Replies

 P: n/a Thomas wrote: Hi, I'm pretty new to the programming world. I got stuck in the following problem. Please guide me about it. Well I'm trying to get the value of (128^100)^2 I've used long double type but to no avail. I even can't get the value of 2^128. How this problem can be solved? Similarly, I was trying to develoop a program in hich we can calculate the value of PI to our desired decimal point, but i got stuck in it. How these sort of problems can be solved in C? What tools C provides us to calculate such values? The C language doesn't provide that stuff directly. But do check out www.snippets.org for a whole bunch of interesting stuff. -- Joe Wright "Everything should be made as simple as possible, but not simpler." --- Albert Einstein --- Jul 14 '07 #2

 P: n/a "Thomas" wrote: Hi, I'm pretty new to the programming world. I got stuck in the following problem. Please guide me about it. Well I'm trying to get the value of (128^100)^2 I've used long double type but to no avail. That's a pretty big number, isn't it? Use a scientific calculator and logs to estimate the value. Then look at the range of numbers that long double handles. You can write a little program and the values in

 P: n/a Thomas said: Hi, I'm pretty new to the programming world. I got stuck in the following problem. Please guide me about it. Well I'm trying to get the value of (128^100)^2 27669029702758120146491942186874884129832195596687 593922941153328644\ 61503706121889747295812490836130522939753216599929 386788554537297860\ 72051766301814526769339210738412304501439841789615 580511966398183532\ 32501575334232440224365258413261224549068647496733 893492858693838936\ 01936689405612487962894280618800556342388396076741 350978743071524441\ 46728820186095678197423949799582894481473506157406 815975220112285819\ 60985268453376 I've used long double type but to no avail. I even can't get the value of 2^128. 340282366920938463463374607431768211456 How this problem can be solved? With programming. Similarly, I was trying to develoop a program in hich we can calculate the value of PI to our desired decimal point, but i got stuck in it. #define PI 3.1415926535897932384626433 If you ever need more than that, it ain't for engineering, that's for sure. How these sort of problems can be solved in C? Using programming and, if you're feeling lazy[1], using other people's programming. Look up "bignums", or "Miracl", or "GMP", on the Web. What tools C provides us to calculate such values? + - * / % = [1] Laziness in a programmer isn't necessarily a bad thing. -- Richard Heathfield Email: -www. +rjh@ Google users: "Usenet is a strange place" - dmr 29 July 1999 Jul 14 '07 #4

 P: n/a Thomas . It works on type double; your implementation might also provide a powl() function that works on type long double. (128^100)^2, or 128^200, or 2^1400, is a much larger number, but even that should be representable in long double on many systems; a binary floating-point representation with an exponent of 12 or more bits would suffice. See also the values of FLT_MAX, DBL_MAX, and LDBL_MAX in . For even larger values, or if your implementation's type long double supports a smaller range than mine does, you'll need to resort to something like an extended-precision library. GNU GMP is one such library. -- Keith Thompson (The_Other_Keith) ks***@mib.org San Diego Supercomputer Center <* "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" Jul 14 '07 #5

 P: n/a "Thomas"

 P: n/a Thomas wrote: Hi, I'm pretty new to the programming world. I got stuck in the following problem. Please guide me about it. Well I'm trying to get the value of (128^100)^2 If by ^ you mean the same thing C does, the answer is 230. If by ^ you mean exponentiation, the answer is 0x100000000000000000000000000000000000\ 00000000000000000000000000000000000\ 00000000000000000000000000000000000\ 00000000000000000000000000000000000\ 00000000000000000000000000000000000\ 00000000000000000000000000000000000\ 00000000000000000000000000000000000\ 00000000000000000000000000000000000\ 00000000000000000000000000000000000\ 00000000000000000000000000000000000 (Both answers derived without benefit of a computer; better double-check my mental arithmetic.) -- Eric Sosman es*****@ieee-dot-org.invalid Jul 14 '07 #7

 P: n/a Richard Heathfield wrote: #define PI 3.1415926535897932384626433 If you ever need more than that, it ain't for engineering, that's for sure. I think that you should have rounded that last digit up. -- pete Jul 14 '07 #8

 P: n/a On Jul 14, 6:40 am, Thomas

 P: n/a On Jul 16, 12:50 pm, user923005 unsigned a = 1e4, b, c = 113316, d, e, f[113316], g, h, i; int main(void) { for (; b = c, c -= 14; i = printf("%04d", e + d / a), e = d % a) while (g = --b * 2) d = h * b + a * (i ? f[b] : a / 5), h = d / --g, f[b] = d - g * h; return 0; } Jul 16 '07 #10

 P: n/a On Jul 17, 12:51 am, user923005 unsigned a = 1e4, b, c = 113316, d, e, f[113316], g, h, i; int main(void) { for (; b = c, c -= 14; i = printf("%04d", e + d / a), e = d % a) while (g = --b * 2) d = h * b + a * (i ? f[b] : a / 5), h = d / --g, f[b] = d - g * h; return 0; } Thanks a lot. Now I have got the idea. The resources i got from above links are enough to keep me occupied. Thanks again. Jul 17 '07 #11

 P: n/a On Jul 17, 12:51 am, user923005 unsigned a = 1e4, b, c = 113316, d, e, f[113316], g, h, i; int main(void) { for (; b = c, c -= 14; i = printf("%04d", e + d / a), e = d % a) while (g = --b * 2) d = h * b + a * (i ? f[b] : a / 5), h = d / --g, f[b] = d - g * h; return 0; } Thanks. now i've got enough resources. Thanks again. Jul 17 '07 #12

### This discussion thread is closed

Replies have been disabled for this discussion.