mathjs/lib/math.min.js
2013-02-17 15:54:48 +01:00

25 lines
21 KiB
JavaScript

/**
* math.js
* An extended math library. Includes a parser, real and complex values, units,
* matrices, strings, and a large set of functions and constants.
* https://github.com/josdejong/mathjs
*
* @version 0.0.3-SNAPSHOT
* @date 2013-02-17
*
* @license
* Copyright (C) 2013 Jos de Jong <wjosdejong@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
(function(){function e(a,i){if(this.constructor!=e)throw Error("Unit constructor must be called with the new operator");this.value=1,this.unit=e.UNIT_NONE,this.prefix=e.PREFIX_NONE,this.hasUnit=!1,this.hasValue=!1,this.fixPrefix=!1,this._init(a,i)}function a(e,i){if(this.constructor!=a)throw Error("Complex constructor must be called with the new operator");this.re=e||0,this.im=i||0}function i(e){return e instanceof Number||"number"==typeof e}function t(a){return a instanceof e}function n(e){var a=typeof e;if("object"==a){if(null==e)return"null";if(e instanceof Array)return"array";if(e&&e.constructor&&e.constructor.name)return e.constructor.name}return a}function s(e,a){var i=n(a),t="Function "+e+" does not support a parameter of type "+i;return"undefined"!=typeof TypeError?new TypeError(t):Error(t)}function f(e,a){if(t(e)){if(a.hasValue)throw Error("Cannot convert to a unit with a value");if(!a.hasUnit)throw Error("Unit expected on the right hand side of function in");var i=a.copy();return i.value=e.value,i.fixPrefix=!0,i}throw s("in",e)}function r(n){if(i(n))return Math.sin(n);if(n instanceof a)return new a(.5*Math.sin(n.re)*(Math.exp(-n.im)+Math.exp(n.im)),.5*Math.cos(n.re)*(Math.exp(n.im)-Math.exp(-n.im)));if(t(n)){if(!n.hasBase(e.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.sin(n.value)}throw s("sin",n)}function o(e){if(i(e))return e>=-1&&1>=e?Math.asin(e):o(new a(e,0));if(e instanceof a){var t=e.re,n=e.im,f=new a(n*n-t*t+1,-2*t*n),r=N(f),u=new a(r.re-n,r.im+t),c=h(u);return new a(c.im,-c.re)}throw s("asin",e)}function u(e){if(i(e))return Math.atan(e);if(e instanceof a){var t=e.re,n=e.im,f=t*t+(1-n)*(1-n),r=new a((1-n*n-t*t)/f,-2*t/f),o=h(r);return new a(-.5*o.im,.5*o.re)}throw s("atan",e)}function c(n){if(i(n))return Math.cos(n);if(n instanceof a)return new a(.5*Math.cos(n.re)*(Math.exp(-n.im)+Math.exp(n.im)),.5*Math.sin(n.re)*(Math.exp(-n.im)-Math.exp(n.im)));if(t(n)){if(!n.hasBase(e.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(n.value)}throw s("cos",n)}function l(n){if(i(n))return Math.tan(n);if(n instanceof a){var f=Math.exp(-4*n.im)+2*Math.exp(-2*n.im)*Math.cos(2*n.re)+1;return new a(2*Math.exp(-2*n.im)*Math.sin(2*n.re)/f,(1-Math.exp(-4*n.im))/f)}if(t(n)){if(!n.hasBase(e.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(n.value)}throw s("tan",n)}function m(e){if(i(e))return e>=-1&&1>=e?Math.acos(e):m(new a(e,0));if(e instanceof a){var t=new a(e.im*e.im-e.re*e.re+1,-2*e.re*e.im),n=N(t),f=new a(n.re-e.im,n.im+e.re),r=h(f);return new a(1.5707963267948966-r.im,r.re)}throw s("acos",e)}function p(e){if(i(e))return Math.exp(e);if(e instanceof a){var t=Math.exp(e.re);return new a(t*Math.cos(e.im),t*Math.sin(e.im))}throw s("exp",e)}function N(e){if(i(e))return e>=0?Math.sqrt(e):N(new a(e,0));if(e instanceof a){var t=Math.sqrt(e.re*e.re+e.im*e.im);return e.im>=0?new a(.5*Math.sqrt(2*(t+e.re)),.5*Math.sqrt(2*(t-e.re))):new a(.5*Math.sqrt(2*(t+e.re)),-.5*Math.sqrt(2*(t-e.re)))}throw s("sqrt",e)}function v(e){if(i(e))return Math.abs(e);if(e instanceof a)return Math.sqrt(e.re*e.re+e.im*e.im);throw s("abs",e)}function h(e){if(i(e))return e>=0?Math.log(e):h(new a(e,0));if(e instanceof a)return new a(Math.log(Math.sqrt(e.re*e.re+e.im*e.im)),Math.atan2(e.im,e.re));throw s("log",e)}var E={type:{},parser:{}};"undefined"!=typeof module&&module.exports!==void 0&&(module.exports=E),"undefined"!=typeof exports&&(exports=E),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return E}),"undefined"!=typeof window&&(window.math=E);var x=1e10,M=function(e,a){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(0/0===e)return"NaN";var i=Math.abs(e);if(i>1e-4&&1e6>i||0==i)return O(e,a)+"";var t=Math.round(Math.log(i)/Math.LN10),n=e/Math.pow(10,t);return O(n,a)+"E"+t},O=function(e,a){return a=void 0!=a?Math.pow(10,a):x,Math.round(e*a)/a};if(!Array.prototype.indexOf){Array.prototype.indexOf=function(e){for(var a=0;this.length>a;a++)if(this[a]==e)return a;return-1};try{console.log("Warning: Ancient browser detected. Please update your browser")}catch(b){}}Array.prototype.forEach||(Array.prototype.forEach=function(e,a){for(var i=0,t=this.length;t>i;++i)e.call(a||this,this[i],i,this)}),E.type.Unit=e,e.prototype.copy=function(){var a=new e;for(var i in this)this.hasOwnProperty(i)&&(a[i]=this[i]);return a},e.endsWith=function(e,a){var i=e.length-a.length,t=e.length;return e.substring(i,t)===a},e.prototype._init=function(a,i){if(void 0!==i){for(var t=e.UNITS,n=!1,s=0,f=t.length;f>s;s++){var r=t[s];if(e.endsWith(i,r.name)){var o=i.length-r.name.length,u=i.substring(0,o),c=r.prefixes[u];if(void 0!==c){this.unit=r,this.prefix=c,this.hasUnit=!0,n=!0;break}}}if(!n)throw Error('String "'+i+'" is no unit')}void 0!==a?(this.value=this._normalize(a),this.hasValue=!0):this.value=this._normalize(1)},e.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},e.prototype._unnormalize=function(e,a){return void 0===a?e/this.unit.value/this.prefix.value-this.unit.offset:e/this.unit.value/a-this.unit.offset},e.isUnit=function(a){for(var i=e.UNITS,t=i.length,n=0;t>n;n++){var s=i[n];if(e.endsWith(a,s.name)){var f=a.length-s.name.length;if(0==f)return!0;var r=a.substring(0,f),o=s.prefixes[r];if(void 0!==o)return!0}}return!1},e.prototype.hasBase=function(e){return void 0===this.unit.base?void 0===e:this.unit.base===e},e.prototype.equalBase=function(e){return this.unit.base===e.unit.base},e.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},e.prototype.toString=function(){if(this.fixPrefix){var a=this._unnormalize(this.value);return M(a)+" "+this.prefix.name+this.unit.name}var i=e.PREFIX_NONE,t=Math.abs(Math.log(this.value/i.value)/Math.LN10-1.5),n=this.unit.prefixes;for(var s in n)if(n.hasOwnProperty(s)){var f=n[s];if(f.scientific){var r=Math.abs(Math.log(this.value/f.value)/Math.LN10-1.5);t>r&&(i=f,t=r)}}var a=this._unnormalize(this.value,i.value);return M(a)+" "+i.name+this.unit.name},e.PREFIXES={NONE:{"":{name:"",value:1,scientific:!0}},SHORT:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:10,scientific:!1},h:{name:"h",value:100,scientific:!1},k:{name:"k",value:1e3,scientific:!0},M:{name:"M",value:1e6,scientific:!0},G:{name:"G",value:1e9,scientific:!0},T:{name:"T",value:1e12,scientific:!0},P:{name:"P",value:1e15,scientific:!0},E:{name:"E",value:1e18,scientific:!0},Z:{name:"Z",value:1e21,scientific:!0},Y:{name:"Y",value:1e24,scientific:!0},d:{name:"d",value:.1,scientific:!1},c:{name:"c",value:.01,scientific:!1},m:{name:"m",value:.001,scientific:!0},u:{name:"u",value:1e-6,scientific:!0},n:{name:"n",value:1e-9,scientific:!0},p:{name:"p",value:1e-12,scientific:!0},f:{name:"f",value:1e-15,scientific:!0},a:{name:"a",value:1e-18,scientific:!0},z:{name:"z",value:1e-21,scientific:!0},y:{name:"y",value:1e-24,scientific:!0}},LONG:{"":{name:"",value:1,scientific:!0},deca:{name:"deca",value:10,scientific:!1},hecto:{name:"hecto",value:100,scientific:!1},kilo:{name:"kilo",value:1e3,scientific:!0},mega:{name:"mega",value:1e6,scientific:!0},giga:{name:"giga",value:1e9,scientific:!0},tera:{name:"tera",value:1e12,scientific:!0},peta:{name:"peta",value:1e15,scientific:!0},exa:{name:"exa",value:1e18,scientific:!0},zetta:{name:"zetta",value:1e21,scientific:!0},yotta:{name:"yotta",value:1e24,scientific:!0},deci:{name:"deci",value:.1,scientific:!1},centi:{name:"centi",value:.01,scientific:!1},milli:{name:"milli",value:.001,scientific:!0},micro:{name:"micro",value:1e-6,scientific:!0},nano:{name:"nano",value:1e-9,scientific:!0},pico:{name:"pico",value:1e-12,scientific:!0},femto:{name:"femto",value:1e-15,scientific:!0},atto:{name:"atto",value:1e-18,scientific:!0},zepto:{name:"zepto",value:1e-21,scientific:!0},yocto:{name:"yocto",value:1e-24,scientific:!0}},BINARY_SHORT:{"":{name:"",value:1,scientific:!0},k:{name:"k",value:1024,scientific:!0},M:{name:"M",value:Math.pow(1024,2),scientific:!0},G:{name:"G",value:Math.pow(1024,3),scientific:!0},T:{name:"T",value:Math.pow(1024,4),scientific:!0},P:{name:"P",value:Math.pow(1024,5),scientific:!0},E:{name:"E",value:Math.pow(1024,6),scientific:!0},Z:{name:"Z",value:Math.pow(1024,7),scientific:!0},Y:{name:"Y",value:Math.pow(1024,8),scientific:!0},Ki:{name:"Ki",value:1024,scientific:!0},Mi:{name:"Mi",value:Math.pow(1024,2),scientific:!0},Gi:{name:"Gi",value:Math.pow(1024,3),scientific:!0},Ti:{name:"Ti",value:Math.pow(1024,4),scientific:!0},Pi:{name:"Pi",value:Math.pow(1024,5),scientific:!0},Ei:{name:"Ei",value:Math.pow(1024,6),scientific:!0},Zi:{name:"Zi",value:Math.pow(1024,7),scientific:!0},Yi:{name:"Yi",value:Math.pow(1024,8),scientific:!0}},BINARY_LONG:{"":{name:"",value:1,scientific:!0},kilo:{name:"kilo",value:1024,scientific:!0},mega:{name:"mega",value:Math.pow(1024,2),scientific:!0},giga:{name:"giga",value:Math.pow(1024,3),scientific:!0},tera:{name:"tera",value:Math.pow(1024,4),scientific:!0},peta:{name:"peta",value:Math.pow(1024,5),scientific:!0},exa:{name:"exa",value:Math.pow(1024,6),scientific:!0},zetta:{name:"zetta",value:Math.pow(1024,7),scientific:!0},yotta:{name:"yotta",value:Math.pow(1024,8),scientific:!0},kibi:{name:"kibi",value:1024,scientific:!0},mebi:{name:"mebi",value:Math.pow(1024,2),scientific:!0},gibi:{name:"gibi",value:Math.pow(1024,3),scientific:!0},tebi:{name:"tebi",value:Math.pow(1024,4),scientific:!0},pebi:{name:"pebi",value:Math.pow(1024,5),scientific:!0},exi:{name:"exi",value:Math.pow(1024,6),scientific:!0},zebi:{name:"zebi",value:Math.pow(1024,7),scientific:!0},yobi:{name:"yobi",value:Math.pow(1024,8),scientific:!0}}},e.PREFIX_NONE={name:"",value:1,scientific:!0},e.BASE_UNITS={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};var d=e.BASE_UNITS,T=e.PREFIXES;e.BASE_UNIT_NONE={},e.UNIT_NONE={name:"",base:e.BASE_UNIT_NONE,value:1,offset:0},e.UNITS=[{name:"meter",base:d.LENGTH,prefixes:T.LONG,value:1,offset:0},{name:"inch",base:d.LENGTH,prefixes:T.NONE,value:.0254,offset:0},{name:"foot",base:d.LENGTH,prefixes:T.NONE,value:.3048,offset:0},{name:"yard",base:d.LENGTH,prefixes:T.NONE,value:.9144,offset:0},{name:"mile",base:d.LENGTH,prefixes:T.NONE,value:1609.344,offset:0},{name:"link",base:d.LENGTH,prefixes:T.NONE,value:.201168,offset:0},{name:"rod",base:d.LENGTH,prefixes:T.NONE,value:5.02921,offset:0},{name:"chain",base:d.LENGTH,prefixes:T.NONE,value:20.1168,offset:0},{name:"angstrom",base:d.LENGTH,prefixes:T.NONE,value:1e-10,offset:0},{name:"m",base:d.LENGTH,prefixes:T.SHORT,value:1,offset:0},{name:"ft",base:d.LENGTH,prefixes:T.NONE,value:.3048,offset:0},{name:"yd",base:d.LENGTH,prefixes:T.NONE,value:.9144,offset:0},{name:"mi",base:d.LENGTH,prefixes:T.NONE,value:1609.344,offset:0},{name:"li",base:d.LENGTH,prefixes:T.NONE,value:.201168,offset:0},{name:"rd",base:d.LENGTH,prefixes:T.NONE,value:5.02921,offset:0},{name:"ch",base:d.LENGTH,prefixes:T.NONE,value:20.1168,offset:0},{name:"mil",base:d.LENGTH,prefixes:T.NONE,value:254e-7,offset:0},{name:"m2",base:d.SURFACE,prefixes:T.SHORT,value:1,offset:0},{name:"sqin",base:d.SURFACE,prefixes:T.NONE,value:64516e-8,offset:0},{name:"sqft",base:d.SURFACE,prefixes:T.NONE,value:.09290304,offset:0},{name:"sqyd",base:d.SURFACE,prefixes:T.NONE,value:.83612736,offset:0},{name:"sqmi",base:d.SURFACE,prefixes:T.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:d.SURFACE,prefixes:T.NONE,value:25.29295,offset:0},{name:"sqch",base:d.SURFACE,prefixes:T.NONE,value:404.6873,offset:0},{name:"sqmil",base:d.SURFACE,prefixes:T.NONE,value:6.4516e-10,offset:0},{name:"m3",base:d.VOLUME,prefixes:T.SHORT,value:1,offset:0},{name:"L",base:d.VOLUME,prefixes:T.SHORT,value:.001,offset:0},{name:"litre",base:d.VOLUME,prefixes:T.LONG,value:.001,offset:0},{name:"cuin",base:d.VOLUME,prefixes:T.NONE,value:16387064e-12,offset:0},{name:"cuft",base:d.VOLUME,prefixes:T.NONE,value:.028316846592,offset:0},{name:"cuyd",base:d.VOLUME,prefixes:T.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:d.VOLUME,prefixes:T.NONE,value:5e-6,offset:0},{name:"tablespoon",base:d.VOLUME,prefixes:T.NONE,value:15e-6,offset:0},{name:"minim",base:d.VOLUME,prefixes:T.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:d.VOLUME,prefixes:T.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:d.VOLUME,prefixes:T.NONE,value:2957353e-11,offset:0},{name:"gill",base:d.VOLUME,prefixes:T.NONE,value:.0001182941,offset:0},{name:"cup",base:d.VOLUME,prefixes:T.NONE,value:.0002365882,offset:0},{name:"pint",base:d.VOLUME,prefixes:T.NONE,value:.0004731765,offset:0},{name:"quart",base:d.VOLUME,prefixes:T.NONE,value:.0009463529,offset:0},{name:"gallon",base:d.VOLUME,prefixes:T.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:d.VOLUME,prefixes:T.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:d.VOLUME,prefixes:T.NONE,value:.1589873,offset:0},{name:"hogshead",base:d.VOLUME,prefixes:T.NONE,value:.238481,offset:0},{name:"fldr",base:d.VOLUME,prefixes:T.NONE,value:36966911e-13,offset:0},{name:"floz",base:d.VOLUME,prefixes:T.NONE,value:2957353e-11,offset:0},{name:"gi",base:d.VOLUME,prefixes:T.NONE,value:.0001182941,offset:0},{name:"cp",base:d.VOLUME,prefixes:T.NONE,value:.0002365882,offset:0},{name:"pt",base:d.VOLUME,prefixes:T.NONE,value:.0004731765,offset:0},{name:"qt",base:d.VOLUME,prefixes:T.NONE,value:.0009463529,offset:0},{name:"gal",base:d.VOLUME,prefixes:T.NONE,value:.003785412,offset:0},{name:"bbl",base:d.VOLUME,prefixes:T.NONE,value:.1173478,offset:0},{name:"obl",base:d.VOLUME,prefixes:T.NONE,value:.1589873,offset:0},{name:"g",base:d.MASS,prefixes:T.SHORT,value:.001,offset:0},{name:"gram",base:d.MASS,prefixes:T.LONG,value:.001,offset:0},{name:"ton",base:d.MASS,prefixes:T.SHORT,value:907.18474,offset:0},{name:"tonne",base:d.MASS,prefixes:T.SHORT,value:1e3,offset:0},{name:"grain",base:d.MASS,prefixes:T.NONE,value:6479891e-11,offset:0},{name:"dram",base:d.MASS,prefixes:T.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:d.MASS,prefixes:T.NONE,value:.028349523125,offset:0},{name:"poundmass",base:d.MASS,prefixes:T.NONE,value:.45359237,offset:0},{name:"hundredweight",base:d.MASS,prefixes:T.NONE,value:45.359237,offset:0},{name:"stick",base:d.MASS,prefixes:T.NONE,value:.115,offset:0},{name:"gr",base:d.MASS,prefixes:T.NONE,value:6479891e-11,offset:0},{name:"dr",base:d.MASS,prefixes:T.NONE,value:.0017718451953125,offset:0},{name:"oz",base:d.MASS,prefixes:T.NONE,value:.028349523125,offset:0},{name:"lbm",base:d.MASS,prefixes:T.NONE,value:.45359237,offset:0},{name:"cwt",base:d.MASS,prefixes:T.NONE,value:45.359237,offset:0},{name:"s",base:d.TIME,prefixes:T.SHORT,value:1,offset:0},{name:"min",base:d.TIME,prefixes:T.NONE,value:60,offset:0},{name:"h",base:d.TIME,prefixes:T.NONE,value:3600,offset:0},{name:"seconds",base:d.TIME,prefixes:T.LONG,value:1,offset:0},{name:"second",base:d.TIME,prefixes:T.LONG,value:1,offset:0},{name:"sec",base:d.TIME,prefixes:T.LONG,value:1,offset:0},{name:"minutes",base:d.TIME,prefixes:T.NONE,value:60,offset:0},{name:"minute",base:d.TIME,prefixes:T.NONE,value:60,offset:0},{name:"hours",base:d.TIME,prefixes:T.NONE,value:3600,offset:0},{name:"hour",base:d.TIME,prefixes:T.NONE,value:3600,offset:0},{name:"day",base:d.TIME,prefixes:T.NONE,value:86400,offset:0},{name:"days",base:d.TIME,prefixes:T.NONE,value:86400,offset:0},{name:"rad",base:d.ANGLE,prefixes:T.NONE,value:1,offset:0},{name:"deg",base:d.ANGLE,prefixes:T.NONE,value:.017453292519943295,offset:0},{name:"grad",base:d.ANGLE,prefixes:T.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:d.ANGLE,prefixes:T.NONE,value:6.283185307179586,offset:0},{name:"A",base:d.CURRENT,prefixes:T.SHORT,value:1,offset:0},{name:"ampere",base:d.CURRENT,prefixes:T.LONG,value:1,offset:0},{name:"K",base:d.TEMPERATURE,prefixes:T.NONE,value:1,offset:0},{name:"degC",base:d.TEMPERATURE,prefixes:T.NONE,value:1,offset:273.15},{name:"degF",base:d.TEMPERATURE,prefixes:T.NONE,value:1/1.8,offset:459.67},{name:"degR",base:d.TEMPERATURE,prefixes:T.NONE,value:1/1.8,offset:0},{name:"kelvin",base:d.TEMPERATURE,prefixes:T.NONE,value:1,offset:0},{name:"celsius",base:d.TEMPERATURE,prefixes:T.NONE,value:1,offset:273.15},{name:"fahrenheit",base:d.TEMPERATURE,prefixes:T.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:d.TEMPERATURE,prefixes:T.NONE,value:1/1.8,offset:0},{name:"mol",base:d.AMOUNT_OF_SUBSTANCE,prefixes:T.NONE,value:1,offset:0},{name:"mole",base:d.AMOUNT_OF_SUBSTANCE,prefixes:T.NONE,value:1,offset:0},{name:"cd",base:d.LUMINOUS_INTENSITY,prefixes:T.NONE,value:1,offset:0},{name:"candela",base:d.LUMINOUS_INTENSITY,prefixes:T.NONE,value:1,offset:0},{name:"N",base:d.FORCE,prefixes:T.SHORT,value:1,offset:0},{name:"newton",base:d.FORCE,prefixes:T.LONG,value:1,offset:0},{name:"lbf",base:d.FORCE,prefixes:T.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:d.FORCE,prefixes:T.NONE,value:4.4482216152605,offset:0},{name:"b",base:d.BIT,prefixes:T.BINARY_SHORT,value:1,offset:0},{name:"bits",base:d.BIT,prefixes:T.BINARY_LONG,value:1,offset:0},{name:"B",base:d.BIT,prefixes:T.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:d.BIT,prefixes:T.BINARY_LONG,value:8,offset:0}],E.type.Complex=a,a.prototype.copy=function(){return new a(this.re,this.im)},a.prototype.toString=function(){var e="";return e=0===this.im?M(this.re):0===this.re?1===this.im?"i":-1===this.im?"-i":M(this.im)+"i":this.im>0?1==this.im?M(this.re)+" + i":M(this.re)+" + "+M(this.im)+"i":-1==this.im?M(this.re)+" - i":M(this.re)+" - "+M(Math.abs(this.im))+"i"},a.doc={name:"Complex",category:"type",syntax:["a + bi","a + b * i"],description:"A complex value a + bi, where a is the real part and b is the complex part, and i is the imaginary number defined as sqrt(-1).",examples:["2 + 3i","sqrt(-4)","(1.2 -5i) * 2"],seealso:["abs","arg","conj","im","re"]},E.E=Math.E,E.LN2=Math.LN2,E.LN10=Math.LN10,E.LOG2E=Math.LOG2E,E.LOG10E=Math.LOG10E,E.PI=Math.PI,E.SQRT1_2=Math.SQRT1_2,E.SQRT2=Math.SQRT2,E.I=new a(0,-1),E.pi=E.PI,E.e=E.E,E.i=E.I,E["in"]=f,f.doc={name:"in",category:"Units",syntax:["x in unit","in(x, unit)"],description:"Change the unit of a value.",examples:["5 inch in cm","3.2kg in g","16 bytes in bits"],seealso:[]},E.sin=r,r.doc={name:"sin",category:"Trigonometry",syntax:["sin(x)"],description:"Compute the sine of x in radians.",examples:["sin(2)","sin(pi / 4) ^ 2","sin(90 deg)","sin(30 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["asin","cos","tan"]},E.asin=o,o.doc={name:"asin",category:"Trigonometry",syntax:["asin(x)"],description:"Compute the inverse sine of a value in radians.",examples:["asin(0.5)","asin(sin(2.3))"],seealso:["sin","acos","asin"]},E.atan=u,u.doc={name:"atan",category:"Trigonometry",syntax:["atan(x)"],description:"Compute the inverse tangent of a value in radians.",examples:["atan(0.5)","atan(tan(2.3))"],seealso:["tan","acos","asin"]},E.cos=c,c.doc={name:"cos",category:"Trigonometry",syntax:["cos(x)"],description:"Compute the cosine of x in radians.",examples:["cos(2)","cos(pi / 4) ^ 2","cos(180 deg)","cos(60 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["acos","sin","tan"]},E.tan=l,l.doc={name:"tan",category:"Trigonometry",syntax:["tan(x)"],description:"Compute the tangent of x in radians.",examples:["tan(0.5)","sin(0.5) / cos(0.5)","tan(pi / 4)","tan(45 deg)"],seealso:["atan","sin","cos"]},E.acos=m,m.doc={name:"acos",category:"Trigonometry",syntax:["acos(x)"],description:"Compute the inverse cosine of a value in radians.",examples:["acos(0.5)","acos(cos(2.3))"],seealso:["cos","acos","asin"]},E.exp=p,p.doc={name:"exp",category:"Arithmetic",syntax:["exp(x)"],description:"Calculate the exponent of a value.",examples:["exp(1.3)","e ^ 1.3","log(exp(1.3))","x = 2.4","(exp(i*x) == cos(x) + i*sin(x)) # Euler's formula"],seealso:["square","multiply","log"]},E.sqrt=N,N.doc={name:"sqrt",category:"Arithmetic",syntax:["sqrt(x)"],description:"Compute the square root value. If x = y * y, then y is the square root of x.",examples:["sqrt(25)","5 * 5","sqrt(-1)"],seealso:["square","multiply"]},E.abs=v,v.doc={name:"abs",category:"Arithmetic",syntax:["abs(x)"],description:"Compute the absolute value.",examples:["abs(3.5)","abs(-4.2)"],seealso:["sign"]},E.log=h,h.doc={name:"log",category:"Arithmetic",syntax:["log(x)"],description:"Compute the natural logarithm of a value.",examples:["log(3.5)","a = log(2.4)","exp(a)","log(1000) / log(10)"],seealso:["exp","logb","log10"]}})();