Tag Archives: maths

PowerShell Maths

A colleague recently popped in a support request after noticing that the Calculator app wasn’t installed on their computer. This prompted an office discussion on how else you can solve sums when sat in front of a computer, and I mentioned you could just use PowerShell.

Open a regular PowerShell window and you can just start typing in basic sums

clip_image001

So addition, subtraction, multiplication, and division work fine- but what else can you do without making it complicated or hard to remember?

PowerShell this comes with the backing of the .NET Maths library, so you can enter [System.Math]:: (or just [Math]:: ) and then tab through possible operations – for example square root (see screenshot), power, trigonometry and so on.

clip_image002

There’s currently 35 methods in this library and you can get a full list of these using the GetMethods property. This example lists them nicely in comma delimited form so you don’t have to scroll this webpage too much 🙂

PS C:\> ([System.Math].GetMethods() |
Select-Object -Unique -Property Name ).Name -join ", "
Abs, Acos, Acosh, Asin, Asinh, Atan, Atan2, Atanh, Cbrt, Ceiling, Cos, Cosh,
Exp, Floor, Log, Log10, Pow, Sin, Sinh, Sqrt, Tan, Tanh, BigMul, DivRem, Clamp,
IEEERemainder, Max, Min, Round, Sign, Truncate, ToString, Equals, GetHashCode,
GetType

So, who needs a graphical Calculator app now?