Advertisement
atm-irbis

Extended Mathematic Library for ObjectIcon

Jul 26th, 2013
3,378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Icon 1.19 KB | None | 0 0
  1. package ext.Math
  2. import
  3.    util(Math),
  4.    ipl.factors(factorial)
  5.  
  6. class ExtMath()
  7. public static const
  8.    syms,
  9.    eiler
  10.  
  11.    private static init()
  12.    syms := &digits++&ucase
  13.    eiler := 0.5772156649015328606065120
  14.    end
  15.  
  16.    public static to_sys(x,n)
  17.       local r,s,i,t,res
  18.       s := list()
  19.       t := list()
  20.       while x >= 1 do {
  21.          r := x%n
  22.          put(s,r)
  23.          x := integer(x/n)
  24.       }
  25.       every i := *s to 1 by -1 do {
  26.          put(t,syms[s[i]+1])
  27.       }
  28.       res:=""
  29.       every i := 1 to *t do {
  30.          res ||:= t[i]
  31.       }
  32.       return res
  33.       end
  34.  
  35.    public static from_sys(x,n)
  36.       local r,t,i
  37.       r := 0
  38.       x := reverse(x)
  39.       every i := 1 to *x do {
  40.      if x[i] == !syms then t := find(x[i],syms)-1
  41.          r +:= t*(n^(i-1))     
  42.       }
  43.       return r
  44.    end
  45.  
  46.    public static to_sys2(x,n1,n2)
  47.    local tmp
  48.    tmp := from_sys(x,n1)
  49.    return to_sys(tmp,n2)
  50.    end
  51.  
  52.    public static root(x,y)
  53.    return x^(1.0/y)
  54.    end
  55.  
  56.    public static discriminant(a,b,c)
  57.    return (b^2) - 4 * a * c
  58.    end
  59.  
  60.    public static sgn(x)
  61.    if x < 0 then return -1 else {
  62.      if x = 0 then return 0 else return 1
  63.    }
  64.    end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement