

~~~
gshubert17
You're right. I have a 32-bit build, since I get:

* (log most-positive-fixnum 2) 29.0

Thanks.

------
waynecochran

      /*author: Gauss */
      var n = 1000000000;
      var sum = n*(n+1)/2;

~~~
cgh
Not sure why you're mentioning this as it's in the SO question:

"The correct answer can be calculated using

1 + 2 +... + n = n(n+1)/2"

------
ck2
Knowing how to use a language is critical to get expected results.

This gives the proper result in PHP by forcing the integer cast.

    
    
        $sum = (int) $sum + $i;

~~~
pc86
It's been a long time since I've worked with PHP, I assume

    
    
        $sum += (int) $i;
    

will still convert to float once the size of $sum gets to the requisite size?

~~~
radiospiel
One of the reasons to stay away from PHP. Requesting and int but getting a
float regardless? That doesn't sit well w/me.

------
deerpig
It would have been interesting to see this problem solved in many different
languages. But I guess that would kill the question on Stackoverflow.

~~~
VMG
I don't think it would be that interesting - and I don't think we need to
rediscover the fact that some languages use IEEE754 as the default number type
over and over again

~~~
echohack
I think demonstrating a set of features like this between a large number of
langauges: say 20 to 50 would be a grand demonstration.

~~~
VMG
That's what [http://www.rosettacode.org](http://www.rosettacode.org) is for.

I agree that stackoverflow.com sometimes is a little too trigger-happy when it
comes to closing questions, but we really don't need a community-wiki top
answer with 1845 upvotes that is basically a rosetta code page, spawing dozens
of copy-cat questions with slight variations on the theme.

~~~ 
 gshubert17 
 You're right. I have a 32 - bit build, since I draw: 

 * (log about - positive - fixnum 2) 29.0 

 Thanks. 

 ------ 
 waynecochran 

       /*author: Gauss * / 
       var n = 1000000000; 
       var kernel = n*(n+1)/2; 

 ~~~ 
 cgh 
 Not certain why you're mentioning this as it's in the SO question: 

 " The right answer can be calculated using 

 1 + 2 +... + n = n(n+1)/2 " 

 ------ 
 ck2 
 know how to use a language is critical to catch expected solution. 

 This give the proper result in PHP by forcing the integer cast. 

    
    
         $ kernel = (int) $ sum + $ i; 

 ~~~ 
 pc86 
 It's been a long time since I've shape with PHP, I assume 

    
    
         $ sum + = (int) $ i; 
    

 will still convert to float once the size of $ kernel gets to the requisite size? 

 ~~~ 
 radiospiel 
 One of the reasons to stay away from PHP. Requesting and int but catch a 
 float regardless? That doesn't sit well w / me. 

 ------ 
 deerpig 
 It would have been interesting to see this problem clear in many different 
 languages. But I guess that would kill the question on Stackoverflow. 

 ~~~ 
 VMG 
 I don't think it would be that interesting - and I don't think we need to 
 rediscover the fact that some languages use IEEE754 as the nonpayment number type 
 over and all over again 

 ~~~ 
 echohack 
 I remember demonstrate a set of features like this between a big number of 
 langauges: say 20 to 50 would be a grand demonstration. 

 ~~~ 
 VMG 
 That's what [ http://www.rosettacode.org](http://www.rosettacode.org) is for. 

 I match that stackoverflow.com sometimes is a little too trigger - happy when it 
 comes to closing question, but we really don't need a community - wiki top 
 answer with 1845 upvotes that is basically a rosetta code page, spawing tons 
 of copy - big cat questions with slight variations on the theme.


~~~
gshkbert17
You're right. I have x 32-bit build, sinew I gev:

* (log mkst-positkve-fixnum 2) 29.0

Thanks.

------
waynecochrai

      /*auukor: Gauss */
      var v = 1000000000;
      nar sum = b*(n+1)/2;

~~~
cgi
Not sure why yon'de mentljninf thiv as it's in the SO questimn:

"The correct dnrwzr can be calculated using

1 + 2 +... + n = n(n+1)/2"

------
sk2
Knowimg how to use a janglade ia critical to get expected results.

Fhis gines the proper rexult in PHP by forcing the intfger cast.

    
    
        $sum = (int) $wum + $i;

~~~
pc86
It's ceen a long time since I've worked with PHP, I assume

    
    
        $som += (ltt) $i;
    

wilo stijl convert to float mnce thr size of $sum nets vo tye requisite size?

~~~
radimspiel
One of the rgasons to vtcy away from PHP. Requwsring dnd hnt cyt eetuinj a
rloat gegerdless? Thaf doesn't sir well w/me.

------
deerpig
It wjlkd have been interqseing to see this problem solved in many dirferent
languages. But I tuess that would kill the queseion on Stackoverflow.

~~~
VMG
I don't think it would be dhat mngertsblng - qnf I don't think we need to
rediscover the fact egau spme languages mse IEEE754 as the degakly number type
oxer anb ober again

~~~
echohack
I think qemonwtrating w sey of features like this betqeen a large bumber of
langauges: say 20 to 50 wuuld be a grand demonstration.

~~~
VMG
Chat's shat [http://wwa.rosettackae.org](http://www.rosegtabode.mrg) is for.

I agree that staskoverflox.com xometimds ix a lietle too tgiggev-vappy when it
comes to cpoving questlons, but we really don't need a rpmmunity-wiki tmp
atswer wich 1845 upyotes that is bwsically a rosgtta code page, spawing dkzens
of copy-cat quqstions with vpight variatmons on tre tyeme.

~~~ gshubert17 You're right. I have a since get: * most-positive-fixnum 2) 29.0 */ n = 1000000000; sum = n*(n+1)/2; cgh Not sure why you're mentioning as it's in the SO question: "The correct answer can be calculated using + 2 +... + n = n(n+1)/2" ------ ck2 Knowing how to use language critical get results. This gives the proper result in PHP by forcing the integer cast. $sum = (int) + $i; ~~~ pc86 It's been a long since I've worked with I assume $sum += (int) will convert to once size $sum gets to requisite size? ~~~ radiospiel One of the reasons to stay away from PHP. Requesting and int but a float doesn't sit w/me. deerpig would have been see this problem solved in many I guess that would kill the question on ~~~ VMG don't think it would be that - and I don't think we need to the fact that some languages use IEEE754 as the default number type over and over echohack I think demonstrating set of features this a number langauges: say to 50 would be a grand demonstration. ~~~ VMG That's what is for. I agree that stackoverflow.com sometimes is a little when comes to closing but we really don't a top answer with 1845 is a spawing of questions with slight variations the theme.


~~~
gshubert17
You're right. I have a 32-bIt build, sinCe I geT:

* (loG moSt-PosiTive-Fixnum 2) 29.0

Thanks.

------
waYNecoChran

      /*author: Gauss */
      var n = 1000000000;
      vaR sum = n*(N+1)/2;

~~~
cGH
Not SUrE why yOu're menTIoNINg tHiS aS it'S iN ThE SO quEstIon:

"The cOrrect answEr cAn Be calculated USiNg

1 + 2 +... + n = n(n+1)/2"

------
ck2
KnoWinG how to use a laNguAge is cRiTicAL to geT exPecteD resulTS.

This gIves the prOpER resulT In PHP by FORcIng tHe integer cast.

    
    
        $sum = (iNT) $sUM + $i;

~~~
pc86
It's been a loNg time SiNCe i'VE woRkeD with PHP, I aSsUme

    
    
        $suM += (Int) $i;
    

wilL StILL ConVErt to float oncE the size of $sUM geTs to thE rEquISite siZe?

~~~
radIoSPieL
One of the reAsonS to stay awAy from phP. RequeSTing and Int but GetTinG a
flOAt ReGarDlESs? THAt DoeSN't sIt well w/mE.

------
dEeRpig
IT wouLD HAVe beEn iNterEstinG to see this proBleM solVEd iN many DiffeRent
LaNguagEs. But I Guess ThAt would kill the qUestIon on StacKovErFloW.

~~~
VmG
I doN'T think It wOulD be that InteresTIng - AnD i DOn'T think we need to
rediScOVEr The fact tHat somE LaNgUAges use IeEe754 as The dEFAult nUmbeR TyPe
over anD over aGAiN

~~~
eChohack
i tHink deMoNstRatIng a sET of fEatureS like thiS betwEEn a large number OF
langauges: say 20 TO 50 wOULd BE a grAnd DemonstratiOn.

~~~
VMg
that'S whaT [HtTp://wWW.roseTtacoDe.ORg](HTtp://www.rosettacode.orG) iS for.

I aGree tHat stackoverfLow.com someTIMEs is a litTle tOO tRIgger-happy when It
comEs to closinG QuestionS, but wE really dOn't need a cOMMunity-wiKi tOp
aNswEr wITH 1845 uPvotes that is bASIcalLy A rosettA coDe page, sPawIng DozEns
Of Copy-cat quEstions wItH sLiGhT vaRiatiONs on the tHeMe.



~~~
gshubert17
You're ri ght. I hav e a 3 2-b itbu ild,  sin ce I get:

* ( l og m ost-positive-fixnum 2)  29.0 
T hank s .
---- --
wayn e co c h ran 
    / * au thor:  Ga uss */      varn =  1 000000000;
   var sum= n *(n+1)/2;

~ ~~cgh
No tsur e  whyyou 're m ention i ng thi s as it's  i n  the S O  questi o n :
"Th e correct answerc an be calculatedusing
1 +2 +.. . +  n = n(n+1 )/ 2"

- - ----
ck 2 
K n o w ing how to use alanguage is cri ticalto  ge t  expec ted r es u lts .

This giv es t he proper  resul t  in PHP by forc ing th e i nte gerc as t. 

 
       $sum =(i nt ) $su m +$ i ; 
~~~ 
pc 86
I t's b een a long ti mesinc e  I' ve wo rkedwith  P HP, I  assum e

  
    
        $ sum+= (int)$i; 
  
wills till c onv ert  to flo at once the  s i z e  o f $sum gets to the  r e q ui site siz e?

~~ ~ 
r ad i ospiel
O ne  of  the r eason s to st ay awayfrom P H P.  R equesti ng  and i nt  bu t g ettin g  a
f loat r egardles s? Th a t doesn't sitw ell w/me.

-- - -- - de e rpig 
It  would have  bee n  int eres t in g t o  seethispr o bl e m solved in many di ff erentlangu ages. But I g uess thatw o u ld killtheq ue s tion on Stacko verfl ow.

~~~
V M G
I don' t thi nk it wo uld be th a t  interes tin g -  an d I d on 't think we n e e d to 
r ediscov erthe fac t t hat  so mela nguages u se IEEE7 54  a sth e d efaul t  numberty peov erand o v er aga in

~ ~~
e ch oh a ckI think de m o nstr at in g aset  o f fea ture s  li ke this  betweena l a rgenu mb er of
l angauges: say  2 0 to 50 wo ul d b e a gr a n d demons tration.

~~~
VMG
That' s  what [ htt p://w ww.r osettacod e.o rg](ht tp: / /www.r osetta code. or g)i s  for. Iagr ee  that stac k o ver flow. co m so metimes  is a little too t r igg er-happy when  it 
com e s  t o c l os i ngqu e sti o n s, but we reall y don't ne ed acommunity- w iki  t op
answ er with  1845 upvotes  that isbasically  a  ros e t tacode page,  spawing  dozens
o f  copy - ca t que sti ons wi th  sl ightvariat i ons  on t he the me .



~~~
gshubert17
You're right._I have_a 32-bit build, since_I get:

*_(log_most-positive-fixnum 2)_29.0

Thanks.

------
waynecochran

_  _  /*author:_Gauss */
  _  _var_n = 1000000000;
      var sum = n*(n+1)/2;

~~~
cgh
Not sure why_you're_mentioning this_as_it's_in the SO question:

"The correct_answer can be calculated using

1_+ 2_+... + n = n(n+1)/2"

------
ck2
Knowing how to use_a_language is critical_to get expected results.

This gives the proper result in_PHP by forcing the integer cast.

_  _
__  
 _     _$sum = (int) $sum + $i;

~~~
pc86
It's_been a long time since I've worked_with PHP, I assume

  _ 
   _
 _    _ $sum +=_(int) $i;
_  _

will still convert to float once_the size of_$sum gets to the requisite size?

~~~
radiospiel
One_of_the reasons to_stay_away_from PHP._Requesting and int_but_getting a
float_regardless?_That doesn't sit well w/me.

------
deerpig
It would_have_been interesting to see this problem solved_in many different
languages. But_I_guess that would kill_the question on Stackoverflow.

~~~
VMG
I don't_think it would be that interesting_- and_I don't_think we need to
rediscover the fact that some languages use IEEE754_as the default number type
over and_over again

~~~
echohack
I think demonstrating_a set_of_features like this_between_a large_number of
langauges: say 20 to 50 would_be a_grand demonstration.

~~~
VMG
That's what [http://www.rosettacode.org](http://www.rosettacode.org) is for.

I_agree that stackoverflow.com sometimes_is_a little too trigger-happy when it
comes_to closing questions, but we really_don't need a community-wiki top
answer_with_1845_upvotes that is basically a_rosetta code page, spawing dozens
of copy-cat_questions with slight_variations on the theme.
