Mathematics

by Oasiscircle
Mathematics procs that BYOND doesn't include. Recommended for every project! [More]
To download this library for your Linux/Mac installation, enter this on your command line:

DreamDownload byond://Oasiscircle.Mathematics##version=1

Emulator users, in the BYOND pager go to File | Open Location and enter this URL:

byond://Oasiscircle.Mathematics##version=1

124 downloads
Version 1
Date added: Nov 4 2012
Last updated: Nov 6 2012
1 fan
Feel free to ask questions. I may add to this library in the future.
This library currently contains the following operations:
  • sum(list/l)
  • squaresum(list/l)
  • mean(list/l)
  • variance(list/l)
  • standarddev(list/l)
  • factorial(n)
  • nPr(n,r)
  • nCr(n,r)
  • integer(n)
  • sign(n)
  • deg2rad(n)
  • rad2deg(n)
  • pyth(a,b)
  • arcpyth(a,c)
  • triarea(a,b,C)
  • tan(n)
  • cot(n)
  • sec(n)
  • csc(n)
  • arctan(n)
  • arccot(n)
  • arcsec(n)
  • arccsc(n)
  • arctan2(x,y)

Comments

IainPeregrine: (Jan 8 2018, 3:22 pm)
runtime error: Division by zero
proc name: arctan2 (/proc/arctan2)
usr: (src)
src: null
call stack:
arctan2(-1, 0)
world: New()


That should return 180
Magnum2k: (Jul 18 2013, 6:48 pm)
Kaiochao wrote:
A few notes on extremely tiny optimization:

I've actually found in my ProcLib tests that sign is (oddly enough) faster this way:
> proc/sign(n) return n && n / abs(n)
>

rather than using a ternary operator or a series of conditionals.
That is odd indeed. I wrote two different versions, and they're both faster than your version by about %10-15. Oddly enough(heh), it uses ternary operators as well.

sign_1(x) return (x < 0) ? -1 : (x > 0)
sign_2(x) return (x > 0) - (x < 0)

I guess DM's compiler is rather crappy at optimizing code.

EDIT: In newer versions, yours might(I haven't tested it yet) actually be faster since Lummox JR optimized abs() along with some other math functions.
TheDarkChakra: (Jan 2 2013, 1:38 pm)
Na looks like that library can't do it
Oasiscircle: (Jan 2 2013, 1:34 pm)
TheDarkChakra: (Jan 2 2013, 11:24 am)
Can you add a proc that can order mobs based on a variable's number? I have mobs and they each have a speed. I want to make it so they are added to a list or something from the order of their speed from highest to lowest so that the faster you are the sooner your turn comes.