PoshCode Archive  Artifact [0ff0018f96]

Artifact 0ff0018f9608c8c54ebaa57fff2fcc5c2b38a107e3f9a00378251b392b4ef469:

  • File divide-integer.ps1 — part of check-in [db9c13417b] at 2018-06-10 14:25:36 on branch trunk — powershell does all dividing by doubles, even integers, so often to simulate a interger division you have to [math]::floor the quotient. Here are some functions to do pure integer division (user: karl prosser size: 885)

# encoding: ascii
# api: powershell
# title: divide integer
# description: powershell does all dividing by doubles, even integers, so often to simulate a interger division you have to [math]::floor the quotient. Here are some functions to do pure integer division
# version: 0.1
# type: function
# author: karl prosser
# license: CC0
# function: divide-integer
# x-poshcode-id: 869
# x-archived: 2015-04-16T00:33:52
# x-published: 2009-02-12T23:08:00
#
#
function divide-integer ([int]$dividend , [int]$divisor ){ [int]$local:remainder = $Null;return [Math]::DivRem($dividend,$divisor,[ref]$local:remainder);}
set-alias i/ divide-integer

i/ 10 3

function divide-integerpipe ([int]$divisor )
{ begin { [int]$local:remainder = $Null}
  process { [Math]::DivRem($_ ,$divisor,[ref]$local:remainder); }
}
set-alias i\ divide-integerpipe
10 | i\ 3

1..10 | i\ 3