Changes in lemon/random.h [487:afd134142111:482:879c55700cd4] in lemon-1.2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/random.h
r487 r482 345 345 }; 346 346 347 template <typename Result, int exp, bool pos = (exp >= 0)> 348 struct ShiftMultiplier { 349 static const Result multiplier() { 350 Result res = ShiftMultiplier<Result, exp / 2>::multiplier(); 351 res *= res; 352 if ((exp & 1) == 1) res *= static_cast<Result>(2.0); 353 return res; 354 } 355 }; 356 347 357 template <typename Result, int exp> 348 struct ShiftMultiplier {358 struct ShiftMultiplier<Result, exp, false> { 349 359 static const Result multiplier() { 350 360 Result res = ShiftMultiplier<Result, exp / 2>::multiplier(); … … 356 366 357 367 template <typename Result> 358 struct ShiftMultiplier<Result, 0 > {368 struct ShiftMultiplier<Result, 0, true> { 359 369 static const Result multiplier() { 360 370 return static_cast<Result>(1.0); … … 363 373 364 374 template <typename Result> 365 struct ShiftMultiplier<Result, 20> {375 struct ShiftMultiplier<Result, -20, true> { 366 376 static const Result multiplier() { 367 377 return static_cast<Result>(1.0/1048576.0); … … 370 380 371 381 template <typename Result> 372 struct ShiftMultiplier<Result, 32> {382 struct ShiftMultiplier<Result, -32, true> { 373 383 static const Result multiplier() { 374 return static_cast<Result>(1.0/42 94967296.0);384 return static_cast<Result>(1.0/424967296.0); 375 385 } 376 386 }; 377 387 378 388 template <typename Result> 379 struct ShiftMultiplier<Result, 53> {389 struct ShiftMultiplier<Result, -53, true> { 380 390 static const Result multiplier() { 381 391 return static_cast<Result>(1.0/9007199254740992.0); … … 384 394 385 395 template <typename Result> 386 struct ShiftMultiplier<Result, 64> {396 struct ShiftMultiplier<Result, -64, true> { 387 397 static const Result multiplier() { 388 398 return static_cast<Result>(1.0/18446744073709551616.0); … … 404 414 405 415 static Result convert(RandomCore<Word>& rnd) { 406 return Shifting<Result, shift +rest>::416 return Shifting<Result, - shift - rest>:: 407 417 shift(static_cast<Result>(rnd() >> (bits - rest))); 408 418 } … … 414 424 415 425 static Result convert(RandomCore<Word>& rnd) { 416 return Shifting<Result, shift +bits>::426 return Shifting<Result, - shift - bits>:: 417 427 shift(static_cast<Result>(rnd())) + 418 428 RealConversion<Result, Word, rest-bits, shift + bits>::
Note: See TracChangeset
for help on using the changeset viewer.