PowerShell 初心者入門 演算方法

四則演算

> 1+2
3

> 3*5
15

> 20/4
5

累乗、平方根、四捨五入

mathクラスを使用する。

>[math]::pow(2,8)
256

>[math]::pow(2,-3)
0.125

> [math]::sqrt(3*1)
1.73205080756888

> [Math]::Round([math]::sqrt(3*1),3)
1.732

バイト単位

> 1KB
1024

> 1MB
1048576

> 1GB
1073741824

2.6MBをKBに変換する
> 2.6MB/1KB
2662.4

System.Math クラスのメソッドを一覧表示

> [System.Math] | Get-Member -Static -MemberType Methods

   TypeName: System.Math

Name            MemberType Definition
----            ---------- ----------
Abs             Method     static sbyte Abs(sbyte value), static int16 Abs(int16 value), static int Abs(int value), ...
Acos            Method     static double Acos(double d)
Asin            Method     static double Asin(double d)
Atan            Method     static double Atan(double d)
Atan2           Method     static double Atan2(double y, double x)
BigMul          Method     static long BigMul(int a, int b)
Ceiling         Method     static decimal Ceiling(decimal d), static double Ceiling(double a)
Cos             Method     static double Cos(double d)
Cosh            Method     static double Cosh(double value)
DivRem          Method     static int DivRem(int a, int b, [ref] int result), static long DivRem(long a, long b, [re...
Equals          Method     static bool Equals(System.Object objA, System.Object objB)
Exp             Method     static double Exp(double d)
Floor           Method     static decimal Floor(decimal d), static double Floor(double d)
IEEERemainder   Method     static double IEEERemainder(double x, double y)
Log             Method     static double Log(double a, double newBase), static double Log(double d)
Log10           Method     static double Log10(double d)
Max             Method     static sbyte Max(sbyte val1, sbyte val2), static byte Max(byte val1, byte val2), static i...
Min             Method     static sbyte Min(sbyte val1, sbyte val2), static byte Min(byte val1, byte val2), static i...
Pow             Method     static double Pow(double x, double y)
ReferenceEquals Method     static bool ReferenceEquals(System.Object objA, System.Object objB)
Round           Method     static double Round(double value, int digits), static double Round(double value, System.M...
Sign            Method     static int Sign(sbyte value), static int Sign(int16 value), static int Sign(int value), s...
Sin             Method     static double Sin(double a)
Sinh            Method     static double Sinh(double value)
Sqrt            Method     static double Sqrt(double d)
Tan             Method     static double Tan(double a)
Tanh            Method     static double Tanh(double value)
Truncate        Method     static decimal Truncate(decimal d), static double Truncate(double d)

Mathクラスの使用例

PS> [System.Math]::Sqrt(9)
3
PS> [System.Math]::Pow(2,3)
8
PS> [System.Math]::Floor(3.3)
3
PS> [System.Math]::Floor(-3.3)
-4
PS> [System.Math]::Ceiling(3.3)
4
PS> [System.Math]::Ceiling(-3.3)
-3
PS> [System.Math]::Max(2,7)
7
PS> [System.Math]::Min(2,7)
2
PS> [System.Math]::Truncate(9.3)
9
PS> [System.Math]::Truncate(-9.3)
-9

その他

> pwd

Path
----
C:\Users\info

コメント