Skip to content

Commit

Permalink
Remove special-case check on rare condition
Browse files Browse the repository at this point in the history
A special case was checked that only occurs when calling uniform with a range of only one element. This was not necessary to keep the math correct and represented a slight slowdown in the common case for no apparent benefit.
  • Loading branch information
Zshazz committed Dec 3, 2013
1 parent 18b8716 commit 3e63ce8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion std/random.d
Expand Up @@ -1347,7 +1347,6 @@ if (isIntegral!(CommonType!(T1, T2)) || isSomeChar!(CommonType!(T1, T2)))
}

assert(upperDist != 0);
if (upperDist == 1) return lower;

alias UpperType = typeof(upperDist);
static assert(UpperType.min == 0);
Expand Down Expand Up @@ -1447,6 +1446,13 @@ unittest
}
assert(sawLB && sawUB);
}

{
foreach (i; 0 .. 30)
{
assert(i == uniform(i, i+1, reproRng));
}
}
}

/**
Expand Down

0 comments on commit 3e63ce8

Please sign in to comment.