Skip to content

Instantly share code, notes, and snippets.

@zippy1981
Created January 10, 2012 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zippy1981/1586729 to your computer and use it in GitHub Desktop.
Save zippy1981/1586729 to your computer and use it in GitHub Desktop.
Powershell [int][Math]::Floor($a/$b) versus [Math]::Floor([int]$a / [int]$b)
<#
In which I prove that that the terser [int][Math]::Floor($a/$b) gives the
same results as the technet recommended [Math]::Floor([int]$a / [int]$b)
Said technet recomendation is available at:
http://technet.microsoft.com/en-us/library/ee176879.aspx
One extra cast is probably slower too.
#>
1.. 1000 | ForEach-Object {
Foreach ($divisor in 2,3,5,7) {
$a = [int][Math]::Floor($_ / $divisor)
$b = [Math]::Floor([int]$_ / [int]$divisor)
if ($a -ne $b) {
"$($a) <> $($b) : $($a)/$($b)"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment