Skip to content

Instantly share code, notes, and snippets.

@ninmonkey
Last active June 5, 2026 19:22
Show Gist options
  • Select an option

  • Save ninmonkey/c241939376be15cbf1feae0c4c8bef0a to your computer and use it in GitHub Desktop.

Select an option

Save ninmonkey/c241939376be15cbf1feae0c4c8bef0a to your computer and use it in GitHub Desktop.
Powershell sugar for exponents
function Pow { param( $base, $pow ) [Math]::Pow( $base, $pow ) }
filter  fPow { param( $Pow ) [Math]::Pow( $_, $pow ) }
filter  IPow { param( $Base ) [Math]::Pow( $base, $_ ) }
function Csv { $input | Join-String -sep ', ' }

3 Different interfaces

Pow 2 7    
    # 128
    
Pow ( Pow 2 18 ) 2
    # 68719476736    
    
Pow ( Pow 16 2 ) ( 1 / 2 )      # === sqrt( 16^2 ) = 16
    # 16
0..16 | fPow 4 | Csv
    # 0, 1, 16, 81, 256, 625, 1296, 2401, 4096, 6561, 10000, 14641, 20736, 28561, 38416, 50625, 65536

0..16 | IPow 2 | Csv
    # 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536      

Some Fun

1 | IPow 2
     # 4
     
1 | IPow 2 | IPow 2 | IPow 2
    # 2
    
   
1 | IPow 2 | IPow 2 | IPow 2
    # 16

Pow 2 2 | FPow 4
    # 256
    
Pow 2 2 | FPow 4 | FPow (1/2)
    # 16
 1 | IPow 2 | IPow 2 | IPow 2 | FPow 2
    # 256
    
1 | IPow 2 | IPow 2 | IPow 2 | FPow (1/2)
    # 4 

Weird names

The names fpow/ipow are confusing I started with them as 'filter/inverse filter'. so that I didn't overwrite the Pow name

They are the same, it's just whether the powers are constant, or come from the pipeline:

Fpow 4 
# is 
Pow -Base $x -Power 4
Ipow 4 
# is 
Pow -Base 4 -Power $x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment