Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > generation of Apocalyptic number

Reply
Thread Tools

generation of Apocalyptic number

 
 
Rajshekhar
Guest
Posts: n/a
 
      09-23-2008
Hi Group,

I woud like to know how can i store a number generated out of 2 to
power of 150
i.e pow(2,150);

mainly i want to knw how can i get the value a large powers of a
number....!

since this crosses all the data type limits ........

can any one tell me the solution ? or c code to do this which will
print it.

cheers
R
 
Reply With Quote
 
 
 
 
Wolfgang Draxinger
Guest
Posts: n/a
 
      09-23-2008
Rajshekhar wrote:

> Hi Group,
>
> I woud like to know how can i store a number generated out of 2
> to power of 150
> i.e pow(2,150);
>
> mainly i want to knw how can i get the value a large powers of
> a number....!
>
> since this crosses all the data type limits ........
>
> can any one tell me the solution ? or c code to do this which
> will print it.


Use a big number library.

You can print it very easily by the way, if binary is ok for you:

char _149zeros[150];
int i;
for(i = 0; i < 149; ++i) {
_149zeros[i] = '0';
}
_149zeros[149] = '\0';
printf("b%c%s", '1', _149zeros);



No really, what you're looking for is a library to deal with
arbitrary large numbers. Google for it, there are plenty of
them.

Wolfgang Draxinger
--
E-Mail address works, Jabber: http://www.velocityreviews.com/forums/(E-Mail Removed), ICQ: 134682867

 
Reply With Quote
 
 
 
 
Rajshekhar
Guest
Posts: n/a
 
      09-23-2008
On Sep 23, 2:47*pm, Wolfgang Draxinger <(E-Mail Removed)>
wrote:
> Rajshekhar wrote:
> > Hi Group,

>
> > I woud like to know how can i store a number generated out of 2
> > to power of 150
> > i.e pow(2,150);

>
> > mainly i want to knw how can i get the value a large powers of
> > a number....!

>
> > since this crosses all the data type limits ........

>
> > can any one tell me the solution ? or c code to do this which
> > will print it.

>
> Use a big number library.
>
> You can print it very easily by the way, if binary is ok for you:
>
> char _149zeros[150];
> int i;
> for(i = 0; i < 149; ++i) {
> * * * * _149zeros[i] = '0';}
>
> _149zeros[149] = '\0';
> printf("b%c%s", '1', _149zeros);
>
>
>
> No really, what you're looking for is a library to deal with
> arbitrary large numbers. Google for it, there are plenty of
> them.
>
> Wolfgang Draxinger
> --
> E-Mail address works, Jabber: (E-Mail Removed), ICQ: 134682867


Hi,

Thanks for the reply

"A number of the form 2^n that contains the digits 666 (i.e., the
beast number) is called an apocalyptic number. is an apocalyptic
number.
The first few such powers are 157, 192, 218, 220, ..."

so to check whether the number has 666 or not first i have to have the
number stored ??

thats exactly what i want
hope u got what i am trying to say..!

cheers
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      09-23-2008
Rajshekhar wrote:
> Hi Group,
>
> I woud like to know how can i store a number generated out of 2 to
> power of 150
> i.e pow(2,150);
>
> mainly i want to knw how can i get the value a large powers of a
> number....!
>
> since this crosses all the data type limits ........
>
> can any one tell me the solution ? or c code to do this which will
> print it.
>
> cheers
> R


If you use the lcc-win compiler you do:
#include <qfloat.h>
#include <stdio.h>
int main(void)
{
qfloat s = pow(2.0q,150.0q);

printf("%50.2qf\n",s);
return 0;
}

Output:

1427247692705959881058285969449495136382746624.00

You can download lcc-win at the address below:

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      09-23-2008
Rajshekhar <(E-Mail Removed)> writes:

> On Sep 23, 2:47┬*pm, Wolfgang Draxinger <(E-Mail Removed)>
> wrote:
>> Rajshekhar wrote:

<snip>
>> > I woud like to know how can i store a number generated out of 2
>> > to power of 150
>> > i.e pow(2,150);

<snip>
>> Use a big number library.

<snip>
>> Wolfgang Draxinger
>> --


Best not to quote sig blocks. Cut them by hand if you need to.

<snip>
> "A number of the form 2^n that contains the digits 666 (i.e., the
> beast number) is called an apocalyptic number. is an apocalyptic
> number.
> The first few such powers are 157, 192, 218, 220, ..."


You mean that contain "666" in decimal or in any base >= 7?

> so to check whether the number has 666 or not first i have to have the
> number stored ??


Well, in some sense yes. But what do you mean by store the number? I
suspect you mean "I need to store it as a decimal string so I look for
666". If that is what you mean, then no, you can store the number in
other forms and still check for it being apocalyptic.

Posting in comp.programming may be better sine the algorithm is not a C
question. There may even be a more suitable group -- I don't know.

--
Ben.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-23-2008
Rajshekhar <(E-Mail Removed)> writes:
> I woud like to know how can i store a number generated out of 2 to
> power of 150
> i.e pow(2,150);
>
> mainly i want to knw how can i get the value a large powers of a
> number....!
>
> since this crosses all the data type limits ........
>
> can any one tell me the solution ? or c code to do this which will
> print it.


If you're only interested in exact powers of 2, you may not need any
kind of extended precision; ordinary floating-point could do the job.

You said in a followup that the exponents you were interested in were
157, 192, 218, and 220. Here's a program that shows 2**n for each of
those values.

#include <stdio.h>
#include <math.h>

int main(void)
{
int expon[] = { 157, 192, 218, 220 };
int i;
for (i = 0; i < sizeof expon / sizeof *expon; i ++) {
printf("%f\n", pow(2.0, expon[i]));
}
return 0;
}

Typically any power of 2 within the range of a floating-point type can
be represented exactly. I don't think printf is actually required to
print such numbers accurately; it does in my implementation. Each
line of output for the above program, when I run it on my system,
includes the sequence "666".

If you need larger exponents, using long double rather than double can
probably get you some extra range (though that's not guaranteed).

Note that if you wanted anything other than powers of 2, or if your
implementation doesn't work the way mine does, the above solution
won't be particularly useful.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Wolfgang Draxinger
Guest
Posts: n/a
 
      09-23-2008
Rajshekhar wrote:

> "A number of the form 2^n that contains the digits 666 (i.e.,
> the beast number) is called an apocalyptic number. is an
> apocalyptic number.


Sorry, I'm not a guy interested in numerology. Number theory yes,
but that should be probably everybody dealing with computer
science.

The only special numbers to me are 0, 1, pi and e. That combined
with Peano's axioms and Euler's formula e^(i * pi) + 1 = 0.
Everything else is just a matter of definition.

So if anybody says to me, a number is apocalyptic, I assume that
to be a metaphor for: My program can't deal with that, due to
lack of resolution.

Wolfgang Draxinger
--
E-Mail address works, Jabber: (E-Mail Removed), ICQ: 134682867

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-23-2008
Wolfgang Draxinger <(E-Mail Removed)> writes:
> Rajshekhar wrote:
>
>> "A number of the form 2^n that contains the digits 666 (i.e.,
>> the beast number) is called an apocalyptic number. is an
>> apocalyptic number.

>
> Sorry, I'm not a guy interested in numerology. Number theory yes,
> but that should be probably everybody dealing with computer
> science.
>
> The only special numbers to me are 0, 1, pi and e. That combined
> with Peano's axioms and Euler's formula e^(i * pi) + 1 = 0.
> Everything else is just a matter of definition.


And Rajshekhar provided a definition, so what's the problem?

> So if anybody says to me, a number is apocalyptic, I assume that
> to be a metaphor for: My program can't deal with that, due to
> lack of resolution.


Your answer is relevant neither to the OP's question nor to C.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      09-23-2008
Rajshekhar wrote:
>
> I woud like to know how can i store a number generated out of 2
> to power of 150 i.e pow(2,150);
>
> mainly i want to knw how can i get the value a large powers of a
> number! since this crosses all the data type limits.
>
> can any one tell me the solution ? or c code to do this which will
> print it.


Try simply using strings. The result will be roughly a 60 char.
string for positive powers.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
 
Reply With Quote
 
Wolfgang Draxinger
Guest
Posts: n/a
 
      09-23-2008
Keith Thompson wrote:

> And Rajshekhar provided a definition, so what's the problem?


He's doing numerology

BTW: I forgot to include 'i' into my set of essential numbers.

>> So if anybody says to me, a number is apocalyptic, I assume
>> that to be a metaphor for: My program can't deal with that,
>> due to lack of resolution.

>
> Your answer is relevant neither to the OP's question nor to C.


Well, the OP's question touches C only insofar, that he is
actually searching for a certain sequence of digits within the
(decimal?) representation of a number. If e.g. he'd look at a
base 5 representation, there would be no occourence of 666 at
all.

The whole topic is IMHO a waste of time. And if the OP really is
just looking for such numbers, well, then he might be better of
with Python, which has big number support built in.

Now I'm getting completely off topic (sorry), this is a Python
3-liner, doing exactly what the OP seems to want:

for i in range(500):
if str(2**i).find('666')>=0:
print "2^%d is 'apocalyptic': %s" % (i, str(2**i))

running it results in

2^157 is 'apocalyptic':
182687704666362864775460604089535377456991567872
2^192 is 'apocalyptic':
62771017353866807638357894232076664161023554444640 34512896
2^218 is 'apocalyptic':
42124916667422874679167211073468172927558038160219 6445017243910144
2^220 is 'apocalyptic':
16849966666969149871666884429387269171023215264087 85780068975640576
2^222 is 'apocalyptic':
67399866667876599486667537717549076684092861056351 43120275902562304
2^224 is 'apocalyptic':
26959946667150639794667015087019630673637144422540 572481103610249216
2^226 is 'apocalyptic':
10783978666860255917866806034807852269454857769016 2289924414440996864
2^243 is 'apocalyptic':
14134776518227074636666380005943348126619871175004 951664972849610340958208
2^245 is 'apocalyptic':
56539106072908298546665520023773392506479484700019 806659891398441363832832
2^247 is 'apocalyptic':
22615642429163319418666208009509357002591793880007 9226639565593765455331328
2^251 is 'apocalyptic':
36185027886661311069865932815214971204146870208012 67626233049500247285301248
2^278 is 'apocalyptic':
48566722305643226772986547670587972666060170976303 4880312953102434726071301302124544
2^285 is 'apocalyptic':
62165404551223330269422781018352605012557018849668 464680057997111644937126566671941632
2^286 is 'apocalyptic':
12433080910244666053884556203670521002511403769933 6929360115994223289874253133343883264
2^287 is 'apocalyptic':
24866161820489332107769112407341042005022807539867 3858720231988446579748506266687766528
2^312 is 'apocalyptic':
83436993590660550093555535397248129476668145404556 74882605631280555545803830627148527195652096
2^355 is 'apocalyptic':
73391955711682288371546268649666782105490079653384 99595960284286038153203483151385824059369952402196 9747968
2^361 is 'apocalyptic':
46970851655476664557789611935786740547513650978166 39741414581943064418050229216886927397996769537406 063869952
2^366 is 'apocalyptic':
15030672529752532658492675819451756975204368313013 24717252666221780613776073349403816767358966251969 94043838464
2^382 is 'apocalyptic':
98505015490986198030697600250359034512699348176163 61666987073351061430442874302652853566563721228910 201656997576704
2^384 is 'apocalyptic':
39402006196394479212279040100143613805079739270465 44666794829340424572177149721061141426625488491564 0806627990306816
2^390 is 'apocalyptic':
25217283965692466695858585664091912835251033133097 88586748690777871726193375821479130513040312634601 011624191379636224
2^394 is 'apocalyptic':
40347654345107946713373737062547060536401653012956 61738797905244594761909401314366608820864500215361 6185987062074179584
2^411 is 'apocalyptic':
52884477503219887916153224642621683186272374637142 49754277190362195246329890490766601513683517722278 780729696200186866434048
2^434 is 'apocalyptic':
44362715105933037753254626946289339254982993206013 06520272767328983394092489000996863959049766623324 9558259375382457149263586525184
2^443 is 'apocalyptic':
22713710134237715329666368996500141698551292521478 68938379656872439497775354368510394347033480511142 3773828800195818060422956300894208
2^478 is 'apocalyptic':
78043713757899805784539930744829157643714953566624 27877147892399063429347049414050300765257658729927 89956732780351655723861993919822071326572544
2^497 is 'apocalyptic':
40917382598701773375164871210344989402708025575538 30986854114210120167245505843193604087615407380196 43860835515945008876152157068235674131666065948672
2^499 is 'apocalyptic':
16366953039480709350065948484137995761083210230215 32394741645684048066898202337277441635046162952078 57544334206378003550460862827294269652666426379468 8

But as I said already, this is a total scam, since a simple
change of base will change the representation, though the
numbers remain the very same.

Wolfgang Draxinger
--
E-Mail address works, Jabber: (E-Mail Removed), ICQ: 134682867

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Number Generation dpi VHDL 4 03-26-2010 10:31 AM
OT: Number Nine, Number Nine, Number Nine Frisbee« MCSE 37 09-26-2005 04:06 PM
Need Help With Random Number Generation Between Upper and Lower Bound ANM Java 2 03-07-2004 07:18 AM
HTML Generation (Next Generation CGI) John W. Long Ruby 4 11-24-2003 04:24 AM
random number generation and Monte Carlo simulation in C++ mescaline C++ 4 09-10-2003 09:01 PM



Advertisments