Changeset 498:afd134142111 in lemonmain for lemon/random.h
 Timestamp:
 02/20/09 21:36:26 (12 years ago)
 Branch:
 default
 Phase:
 public
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

lemon/random.h
r491 r498 345 345 }; 346 346 347 template <typename Result, int exp , bool pos = (exp >= 0)>347 template <typename Result, int exp> 348 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 357 template <typename Result, int exp>358 struct ShiftMultiplier<Result, exp, false> {359 349 static const Result multiplier() { 360 350 Result res = ShiftMultiplier<Result, exp / 2>::multiplier(); … … 366 356 367 357 template <typename Result> 368 struct ShiftMultiplier<Result, 0 , true> {358 struct ShiftMultiplier<Result, 0> { 369 359 static const Result multiplier() { 370 360 return static_cast<Result>(1.0); … … 373 363 374 364 template <typename Result> 375 struct ShiftMultiplier<Result, 20, true> {365 struct ShiftMultiplier<Result, 20> { 376 366 static const Result multiplier() { 377 367 return static_cast<Result>(1.0/1048576.0); … … 380 370 381 371 template <typename Result> 382 struct ShiftMultiplier<Result, 32, true> {372 struct ShiftMultiplier<Result, 32> { 383 373 static const Result multiplier() { 384 return static_cast<Result>(1.0/42 4967296.0);374 return static_cast<Result>(1.0/4294967296.0); 385 375 } 386 376 }; 387 377 388 378 template <typename Result> 389 struct ShiftMultiplier<Result, 53, true> {379 struct ShiftMultiplier<Result, 53> { 390 380 static const Result multiplier() { 391 381 return static_cast<Result>(1.0/9007199254740992.0); … … 394 384 395 385 template <typename Result> 396 struct ShiftMultiplier<Result, 64, true> {386 struct ShiftMultiplier<Result, 64> { 397 387 static const Result multiplier() { 398 388 return static_cast<Result>(1.0/18446744073709551616.0); … … 414 404 415 405 static Result convert(RandomCore<Word>& rnd) { 416 return Shifting<Result,  shift rest>::406 return Shifting<Result, shift + rest>:: 417 407 shift(static_cast<Result>(rnd() >> (bits  rest))); 418 408 } … … 424 414 425 415 static Result convert(RandomCore<Word>& rnd) { 426 return Shifting<Result,  shift bits>::416 return Shifting<Result, shift + bits>:: 427 417 shift(static_cast<Result>(rnd())) + 428 418 RealConversion<Result, Word, restbits, shift + bits>::
Note: See TracChangeset
for help on using the changeset viewer.