PoshCode Archive  Artifact Content

Artifact 32f4faacf77ea41ac043d1fc75c2dc1d0dca275dbdc1c09e519a1304da222991:

  • File divide-integer.ps1 — part of check-in [717d3a6768] at 2018-06-10 14:15:45 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: 886)

# 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: 6438
# x-archived: 2016-07-04T03:04:37
# x-published: 2016-07-01T19:01: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