Math Identifiers

By Firstmate on Jan 30, 2009

I don't know how useful this will be to other people, but I use some of these quite often. Anyways, this has 8 (so far) mathematical identifiers. I will try to add more as requests or as I need them.

It has:
$ispo(N): Returns $true if N is a positive number
$isneg(N): Returns $true if N is a negative number
$average(N1 N2 N3...): Returns the average of the series (Separated by a space)
$max(N1 N2 N3...): Returns maximum number from a series (Separated by a space)
$min(N1 N2 N3...): Returns minimum number from a series (Separated by a space)
$e: Returns the mathematical constant for e. (useful in things like a natural logarithm)
$logb(N,B): Returns logarithm of N with base B
$factor(N): Returns a list of factors for N (must be greater than 3)
$angle(N): Returns a conversion from either degree-radians or radians-degree. The desired output should be used as the property. (e.g. $angle(5pi).degree)

New:
$even(N): Returns true if N is even
$odd(N): Returns true if N is odd.
$nDeriv(N,f(x)): Returns the derivative at N from the equation f(x). Also assuming f(x) is derivable at that point. (e.g. $nDeriv(2,x^2) will give you 4)

I do take requests! So please if you have any more, do share so I can add to this.

Thanks:
korvin

alias ispos { return $iif($1 > 0,$true,$false) }
alias isneg { return $iif($1 < 0,$true,$false) }
alias average { return $calc(($replace($1-,$chr(32),+)) / $numtok($1,32)) }
alias min { var %x = $numtok($1-,32), %i = 0, %p = $calc(10^308) | while (%i < %x) { inc %i | if ($gettok($1-,%i,32) isnum && $gettok($1-,%i,32) < %p) { %p = $gettok($1-,%i,32) } } | return %p }
alias max { var %x = $numtok($1-,32), %i = 0, %p = 0 | while (%i < %x) { inc %i | if ($gettok($1-,%i,32) isnum && $gettok($1-,%i,32) > %p) { %p = $gettok($1-,%i,32) } } | return %p }
alias e { return 2.71828182845904523536 }
alias even { return $iif(2 // $1,$true,$false) }
alias odd { return $iif(2 \\ $1,$true,$false) }
alias nDeriv { var %x $1, %eq $2- | return $calc(($replace(%eq,x,(%x + .001)) - $replace(%eq,x,(%x - .001))) /((%x + .001) - (%x - .001))) }

alias angle {
  if ($1 && $prop) {
    if ($prop == degree) { return $calc($1 * (180/$pi)) }
    if ($prop == radian) { return $calc(($1 * $pi) / 180) }
  }
}
alias logb {
  if ($1 && $2) {
    var %n = $1, %b = $2
    if ((%n !== 0) && (%n > 0) && (%b !== 0) && (%b > 0)) {
      return $calc($log(%n) / $log(%b))
    }
    else { echo -a *$logb Invalid Parametersx | halt }
  }
  else { echo -a *$logb Invalid Parameters | halt }
}
alias factor {
  var %num = $1, %i = 1, %p 
  while (%i < $calc(%num / 2)) {
    if ($istok(%p,$calc(%num / %i),32) == $false) {
      if ($calc(%num % %i) == 0) { 
        var %p = %p %i $calc(%num / %i)
      }
    }
    inc %i
  }
  return $sorttok(%p,32,n)
}

Comments

Sign in to comment.
dashh   -  Feb 23, 2009

$pi <- a hidden id in mirc return the pi number.

3.14159265358979323846

xD

;- prop's
;         cir ->  with a diameter get a perimeter of a circle (diam)
;         rad -> with a radius get a perimeter of the diameter
;         sqr -> perimeter of a square with a side.
;- no prop -> get any perimeter of a polygon.
;-  - - - - - - - -  by dashh xD

alias perimeter {
  if ( $prop = cir ) { return $calc($1 * $pi) }
  if ( $prop = rad ) { return $calc((2 * $pi) * $1) }
  if ( $prop = sqr ) { return $calc(4 * $1 ) }
  return $calc($replace($remove($1-,+,-),$chr(32),$chr(43)))
}
 Respond  
Firstmate   -  Jan 31, 2009

Added and fixed. Thanks.

Any other ones?

Added:
$even
$odd
$nDeriv

 Respond  
Korvin   -  Jan 31, 2009

mybad =]

 Respond  
TheImrac   -  Jan 31, 2009

Korvin, the $1 and 2 should be switched, good addition though:

alias even { return $iif(2 // $1,$true,$false) }
alias odd { return $iif(2 \\ $1,$true,$false) }
 Respond  
Korvin   -  Jan 31, 2009

well.. i cant remember if there is an even/odd feature with mirc

alias even { return $iif($1 // 2,$true,$false) }
alias odd { return $iif($1 \\ 2,$true,$false) }
 Respond  
TheImrac   -  Jan 30, 2009

Oh BTW technically, 0 could be postive or negative. so you might want to do >= and <=, but I wasn't sure.

 Respond  
Firstmate   -  Jan 30, 2009

@bluepower: Not really. Just adds some more identifiers to work with.

@TheImrac: Hmm, I'll update those. I've had those for quite a while so I didn't really update those.

Edit: I realize now why I didn't use something like your $max identifier.
If you do something like $max($ip a 21 13) = $ip
$min($ip a 21 13) = a

 Respond  
Bluepower10   -  Jan 30, 2009

Is this like an IRC Calculator? Or what is it..?

 Respond  
TheImrac   -  Jan 30, 2009

Alot of these could be consolidated.

alias ispos { return $iif($1 > 0,$true,$false) }
alias isneg { return $iif($1 < 0,$true,$false) }
alias average { return $calc(($replace($1,$chr(32),+)) / $numtok($1,32)) }
alias min { return $gettok($sorttok($1,32,n),1,32) }
alias max { return $gettok($sorttok($1,32,nr),1,32) }
 Respond  
Aucun50   -  Jan 30, 2009

Looks neat.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.