1.#inf "immediately"


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: 1.#inf "immediately"

  1. #1
    Join Date
    Mar 2010
    Posts
    61

    1.#IO "immediately"

    hey guys

    when i want to print out amount of "seed"("seed*=pow(x,y)")-seed is a long double variable,it print"1.#INF" and after some changes it print "1.#IO",in big numbers.

    how to solve this(any suggestion)?

    thanks in advance.

    ask for immediately answer.
    Last edited by badguy; 04-11-2010 at 11:53 AM. Reason: 1.#IO "immediately"

  2. #2
    Join Date
    Dec 2003
    Posts
    3,366
    your result is too large. to fix it you may need to use a large number class, such as can be found on BOOST.ORG site, or other sites. What value did you have for x, y and initial value of seed?

    Basically, the biggest floating point value you can support on most machines is 10-bytes, and that can be a pain, ususally its just 8 bytes, which has limitations. For integers usually 64 bit is all you have, which also is not that big really.

    If you can, try to factor or reduce the equation somehow to avoid the problem first. For example, after 10 every factorial is 10 X value, so you can store them with one less exponent after 10 (there are several factors that can be removed this way to save space on factorials but eventually you have to use bigger number objects).
    Last edited by jonnin; 04-11-2010 at 04:15 PM.

  3. #3
    Join Date
    Mar 2010
    Posts
    61
    the value that i have is sth like this (i know this is ridiculous)

    long double seed=24;
    for(int n=0;n<=380;n++,year++){
    cout<<setw(4)<<year;
    for(float i=0.05;i<=0.10;i+=0.01){
    seed*=pow((1+i),n);
    cout<<setw(12)<<seed;
    }
    so what is the point?

  4. #4
    Join Date
    Dec 2003
    Posts
    3,366
    That code does not go INF immediately. It prints this, as expected:

    24
    24
    24
    24
    24
    24
    25.2
    26.712
    28.5818
    30.8684
    33.6465
    37.0112
    40.8048
    45.8483
    52.4917
    61.2264
    72.7431
    88.0191
    101.893
    121.356
    148.667
    187.277
    242.529
    322.807
    392.374
    495.362
    649.319
    883.392
    1246.98
    1825.7
    2330.11
    3118.21
    4373.46
    6426.04
    9887.27
    15923.5
    21339.1
    30269.9
    45426.9
    72086.8
    120897
    214176
    301367
    453145
    727651
    1.24707e+006
    2.27969e+006
    4.44247e+006
    6.56354e+006
    1.04613e+007
    1.79744e+007
    3.32695e+007
    6.62915e+007
    1.42102e+008
    2.20446e+008
    3.72439e+008
    6.84715e+008
    1.36875e+009
    2.97278e+009
    7.00965e+009
    1.1418e+010
    2.04478e+010
    4.0224e+010
    8.68407e+010
    2.05584e+011
    5.33231e+011
    9.12006e+011
    1.73126e+012
    3.64404e+012
    8.4966e+012
    2.19249e+013
    6.25542e+013
    1.12338e+014
    2.26046e+014
    5.091e+014
    1.282e+015
    3.60584e+015
    1.13167e+016
    2.13393e+016
    4.55151e+016
    1.09684e+017
    2.98301e+017
    9.14532e+017
    3.15721e+018
    6.25106e+018
    1.4133e+019
    3.64425e+019
    1.07039e+020
    3.57695e+020
    1.35835e+021
    2.8239e+021
    6.76764e+021
    1.86721e+022
    5.92312e+022
    2.15749e+023
    9.01236e+023
    1.96728e+024
    4.99759e+024
    1.47537e+025
    5.05454e+025
    2.00681e+026
    9.22123e+026
    2.11352e+027
    5.69123e+027
    1.79776e+028
    6.65173e+028
    2.87863e+029
    1.45499e+030
    3.50161e+030
    9.99478e+030
    3.37817e+031
    1.34992e+032
    6.36776e+032
    3.54043e+033
    8.94647e+033
    2.70684e+034
    9.78937e+034
    4.2248e+035
    2.17225e+036
    1.32853e+037
    3.52498e+037
    1.13051e+038
    4.37472e+038
    2.03904e+039
    1.14276e+040
    7.68793e+040
    2.14183e+041
    7.28127e+041
    3.01486e+042
    1.51763e+043
    9.27092e+043
    6.86071e+044
    2.00693e+045
    7.23206e+045
    3.20409e+046
    1.74192e+047
    1.15988e+048
    9.44172e+048
    2.90004e+049
    1.10774e+050
    5.25129e+050
    3.08328e+051
    2.23781e+052
    2.0038e+053
    6.46245e+053
    2.6166e+054
    1.32724e+055
    8.41626e+055
    6.65818e+056
    6.55813e+057
    2.22081e+058
    9.53143e+058
    5.17312e+059
    3.5428e+060
    3.05499e+061
    3.31e+062
    1.17692e+063
    5.35427e+063
    3.10942e+064
    2.29984e+065
    2.16166e+066
    2.5763e+067
    9.6185e+067
    4.63837e+068
    2.88222e+069
    2.30234e+070
    2.35877e+071
    3.09235e+072
    1.21224e+073
    6.19657e+073
    4.12e+074
    3.55438e+075
    3.96923e+076
    5.72402e+077
    2.35608e+078
    1.27661e+079
    9.08217e+079
    8.46212e+080
    1.03003e+082
    1.63394e+083
    7.06178e+083
    4.05592e+084
    3.08748e+085
    3.10682e+086
    4.12204e+087
    7.19272e+088
    3.26408e+089
    1.9872e+090
    1.6186e+091
    1.75904e+092
    2.54389e+093
    4.88283e+094
    2.32664e+095
    1.50147e+096
    1.30857e+097
    1.53588e+098
    2.42106e+099
    5.11179e+100
    2.55752e+101
    1.74949e+102
    1.63146e+103
    2.06805e+104
    3.55334e+105
    8.25268e+106
    4.33541e+107
    3.14361e+108
    3.13674e+109
    4.29424e+110
    8.04244e+111
    2.05466e+113
    1.13335e+114
    8.71101e+114
    9.3004e+115
    1.3751e+117
    2.80712e+118
    7.88871e+119
    4.56899e+120
    3.72246e+121
    4.25253e+122
    6.79051e+123
    1.51098e+125
    4.67083e+126
    2.84052e+127
    2.45309e+128
    2.99857e+129
    5.17123e+130
    1.25422e+132
    4.26486e+133
    2.72331e+134
    2.49298e+135
    3.26064e+136
    6.07305e+137
    1.60551e+139
    6.00533e+140
    4.02641e+141
    3.90702e+142
    5.46782e+143
    1.09987e+145
    3.16939e+146
    1.30404e+148
    9.1804e+148
    9.44268e+149
    1.41399e+151
    3.07183e+152
    9.64847e+153
    4.36683e+155
    3.22795e+156
    3.51938e+157
    5.639e+158
    1.32305e+160
    4.52964e+161
    2.25509e+163
    1.7503e+164
    2.02283e+165
    3.468e+166
    8.78773e+167
    3.27937e+169
    1.79591e+171
    1.4636e+172
    1.79297e+173
    3.2891e+174
    9.00118e+175
    3.66134e+177
    2.20559e+179
    1.88735e+180
    2.45081e+181
    4.81058e+182
    1.42182e+184
    6.30391e+185
    4.17723e+187
    3.75324e+188
    5.16617e+189
    1.08503e+191
    3.46346e+192
    1.6738e+194
    1.22004e+196
    1.15101e+197
    1.67938e+198
    3.77402e+199
    1.30106e+201
    6.85358e+202
    5.49517e+204
    5.44349e+205
    8.41883e+206
    2.02437e+208
    7.53716e+209
    4.32767e+211
    3.8169e+213
    3.97005e+214
    6.50843e+215
    1.67455e+217
    6.73348e+218
    4.21417e+220
    4.08848e+222
    4.46515e+223
    7.7593e+224
    2.13613e+226
    9.27669e+227
    6.32838e+229
    6.75359e+231
    7.74459e+232
    1.42656e+234
    4.20223e+235
    1.97092e+237
    1.46553e+239
    1.7204e+241
    2.07149e+242
    4.04464e+243
    1.27484e+245
    6.45753e+246
    5.23382e+248
    6.75844e+250
    8.54454e+251
    1.76845e+253
    5.96417e+254
    3.26276e+256
    2.88247e+258
    4.09435e+260
    5.43521e+261
    1.19241e+263
    4.30296e+264
    2.5423e+266
    2.44812e+268
    3.82512e+270
    5.33171e+271
    1.23989e+273
    4.78748e+274
    3.05485e+276
    3.20643e+278
    5.51097e+280
    8.06562e+281
    1.9882e+283
    8.21425e+284
    5.66077e+286
    6.4764e+288
    1.22442e+291
    1.88162e+292
    4.91653e+293
    2.17346e+295
    1.61764e+297
    2.01728e+299
    4.19525e+301
    6.76935e+302
    1.87491e+304
    8.86863e+305
    7.12872e+307
    1.#INF
    1.#INF
    1.#INF
    1.#INF
    ... lots more infinitys

    Press any key to continue . . .

  5. #5
    Join Date
    Dec 2003
    Posts
    3,366
    What is happening is the *= statement is growing the value at a rapid rate. The power function is OK, the values from it are small, but if you just do this:

    y = 2;
    for(x = 1; x < 1000; x++)
    y *= 2;

    it will be bigger than you can store in short order, what you have is similar to this.

  6. #6
    Join Date
    Mar 2010
    Posts
    61
    i know that but the problem says you must print out every (n=380) result which goes to infinite

  7. #7
    Join Date
    Dec 2003
    Posts
    3,366
    then you need to use a large number class. Its like trying to park a semi with a trailer in a house garage... it will not fit.

    An 8 byte floating point number holds up to 1.7 X 10^308 with 15 digits or so of precision. If you need something bigger than this, you must use those classes.

    Note that long double is at least as big as a double, and a double is 8 byte floating point. A long double may be 10 bytes, but it may just be 8 bytes, in other words, depends on your compiler.

    If this is an assignment, in an intro level class, odds are your job is just to understand this limitation and not to fix it.

  8. #8
    Join Date
    Mar 2010
    Posts
    61
    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center