mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
24 lines
19 KiB
JavaScript
24 lines
19 KiB
JavaScript
/**
|
|
* Math2
|
|
* An extended Math library for Javascript
|
|
* https://github.com/josdejong/math2
|
|
*
|
|
* @version 0.0.2
|
|
* @date 2013-02-16
|
|
*
|
|
* @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(e){return e instanceof a}function s(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 f(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 r(e,a){if(s(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 f("in",e)}function o(n){if(i(n))return Math.sin(n);if(t(n))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(s(n)){if(!n.hasBase(e.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.sin(n.value)}throw f("sin",n)}function u(n){if(i(n))return Math.cos(n);if(t(n))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(s(n)){if(!n.hasBase(e.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(n.value)}throw f("cos",n)}function l(n){if(i(n))return Math.tan(n);if(t(n)){var r=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)/r,(1-Math.exp(-4*n.im))/r)}if(s(n)){if(!n.hasBase(e.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(n.value)}throw f("tan",n)}function c(e){if(i(e))return Math.exp(e);if(t(e)){var s=Math.exp(e.re);return new a(s*Math.cos(e.im),s*Math.sin(e.im))}throw f("exp",e)}function m(e){if(i(e))return e>=0?Math.sqrt(e):m(new a(e,0));if(t(e)){var s=Math.sqrt(e.re*e.re+e.im*e.im);return e.im>=0?new a(.5*Math.sqrt(2*(s+e.re)),.5*Math.sqrt(2*(s-e.re))):new a(.5*Math.sqrt(2*(s+e.re)),-.5*Math.sqrt(2*(s-e.re)))}throw f("sqrt",e)}function p(e){if(i(e))return Math.abs(e);if(t(e))return Math.sqrt(e.re*e.re+e.im*e.im);throw f("abs",e)}function N(e){if(i(e))return e>=0?Math.log(e):N(new a(e,0));if(t(e))return new a(Math.log(Math.sqrt(e.re*e.re+e.im*e.im)),Math.atan2(e.im,e.re));throw f("log",e)}var v={type:{},parser:{}};"undefined"!=typeof module&&module.exports!==void 0&&(module.exports=v),"undefined"!=typeof exports&&(exports=v),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return v}),"undefined"!=typeof window&&(window.math2=v);var E=1e10,h=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 x(e,a)+"";var t=Math.round(Math.log(i)/Math.LN10),s=e/Math.pow(10,t);return x(s,a)+"E"+t},x=function(e,a){return a=void 0!=a?Math.pow(10,a):E,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(O){}}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)}),v.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,s=!1,n=0,f=t.length;f>n;n++){var r=t[n];if(e.endsWith(i,r.name)){var o=i.length-r.name.length,u=i.substring(0,o),l=r.prefixes[u];if(void 0!==l){this.unit=r,this.prefix=l,this.hasUnit=!0,s=!0;break}}}if(!s)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,s=0;t>s;s++){var n=i[s];if(e.endsWith(a,n.name)){var f=a.length-n.name.length;if(0==f)return!0;var r=a.substring(0,f),o=n.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 h(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),s=this.unit.prefixes;for(var n in s)if(s.hasOwnProperty(n)){var f=s[n];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 h(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 b=e.BASE_UNITS,M=e.PREFIXES;e.BASE_UNIT_NONE={},e.UNIT_NONE={name:"",base:e.BASE_UNIT_NONE,value:1,offset:0},e.UNITS=[{name:"meter",base:b.LENGTH,prefixes:M.LONG,value:1,offset:0},{name:"inch",base:b.LENGTH,prefixes:M.NONE,value:.0254,offset:0},{name:"foot",base:b.LENGTH,prefixes:M.NONE,value:.3048,offset:0},{name:"yard",base:b.LENGTH,prefixes:M.NONE,value:.9144,offset:0},{name:"mile",base:b.LENGTH,prefixes:M.NONE,value:1609.344,offset:0},{name:"link",base:b.LENGTH,prefixes:M.NONE,value:.201168,offset:0},{name:"rod",base:b.LENGTH,prefixes:M.NONE,value:5.02921,offset:0},{name:"chain",base:b.LENGTH,prefixes:M.NONE,value:20.1168,offset:0},{name:"angstrom",base:b.LENGTH,prefixes:M.NONE,value:1e-10,offset:0},{name:"m",base:b.LENGTH,prefixes:M.SHORT,value:1,offset:0},{name:"ft",base:b.LENGTH,prefixes:M.NONE,value:.3048,offset:0},{name:"yd",base:b.LENGTH,prefixes:M.NONE,value:.9144,offset:0},{name:"mi",base:b.LENGTH,prefixes:M.NONE,value:1609.344,offset:0},{name:"li",base:b.LENGTH,prefixes:M.NONE,value:.201168,offset:0},{name:"rd",base:b.LENGTH,prefixes:M.NONE,value:5.02921,offset:0},{name:"ch",base:b.LENGTH,prefixes:M.NONE,value:20.1168,offset:0},{name:"mil",base:b.LENGTH,prefixes:M.NONE,value:254e-7,offset:0},{name:"m2",base:b.SURFACE,prefixes:M.SHORT,value:1,offset:0},{name:"sqin",base:b.SURFACE,prefixes:M.NONE,value:64516e-8,offset:0},{name:"sqft",base:b.SURFACE,prefixes:M.NONE,value:.09290304,offset:0},{name:"sqyd",base:b.SURFACE,prefixes:M.NONE,value:.83612736,offset:0},{name:"sqmi",base:b.SURFACE,prefixes:M.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:b.SURFACE,prefixes:M.NONE,value:25.29295,offset:0},{name:"sqch",base:b.SURFACE,prefixes:M.NONE,value:404.6873,offset:0},{name:"sqmil",base:b.SURFACE,prefixes:M.NONE,value:6.4516e-10,offset:0},{name:"m3",base:b.VOLUME,prefixes:M.SHORT,value:1,offset:0},{name:"L",base:b.VOLUME,prefixes:M.SHORT,value:.001,offset:0},{name:"litre",base:b.VOLUME,prefixes:M.LONG,value:.001,offset:0},{name:"cuin",base:b.VOLUME,prefixes:M.NONE,value:16387064e-12,offset:0},{name:"cuft",base:b.VOLUME,prefixes:M.NONE,value:.028316846592,offset:0},{name:"cuyd",base:b.VOLUME,prefixes:M.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:b.VOLUME,prefixes:M.NONE,value:5e-6,offset:0},{name:"tablespoon",base:b.VOLUME,prefixes:M.NONE,value:15e-6,offset:0},{name:"minim",base:b.VOLUME,prefixes:M.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:b.VOLUME,prefixes:M.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:b.VOLUME,prefixes:M.NONE,value:2957353e-11,offset:0},{name:"gill",base:b.VOLUME,prefixes:M.NONE,value:.0001182941,offset:0},{name:"cup",base:b.VOLUME,prefixes:M.NONE,value:.0002365882,offset:0},{name:"pint",base:b.VOLUME,prefixes:M.NONE,value:.0004731765,offset:0},{name:"quart",base:b.VOLUME,prefixes:M.NONE,value:.0009463529,offset:0},{name:"gallon",base:b.VOLUME,prefixes:M.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:b.VOLUME,prefixes:M.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:b.VOLUME,prefixes:M.NONE,value:.1589873,offset:0},{name:"hogshead",base:b.VOLUME,prefixes:M.NONE,value:.238481,offset:0},{name:"fldr",base:b.VOLUME,prefixes:M.NONE,value:36966911e-13,offset:0},{name:"floz",base:b.VOLUME,prefixes:M.NONE,value:2957353e-11,offset:0},{name:"gi",base:b.VOLUME,prefixes:M.NONE,value:.0001182941,offset:0},{name:"cp",base:b.VOLUME,prefixes:M.NONE,value:.0002365882,offset:0},{name:"pt",base:b.VOLUME,prefixes:M.NONE,value:.0004731765,offset:0},{name:"qt",base:b.VOLUME,prefixes:M.NONE,value:.0009463529,offset:0},{name:"gal",base:b.VOLUME,prefixes:M.NONE,value:.003785412,offset:0},{name:"bbl",base:b.VOLUME,prefixes:M.NONE,value:.1173478,offset:0},{name:"obl",base:b.VOLUME,prefixes:M.NONE,value:.1589873,offset:0},{name:"g",base:b.MASS,prefixes:M.SHORT,value:.001,offset:0},{name:"gram",base:b.MASS,prefixes:M.LONG,value:.001,offset:0},{name:"ton",base:b.MASS,prefixes:M.SHORT,value:907.18474,offset:0},{name:"tonne",base:b.MASS,prefixes:M.SHORT,value:1e3,offset:0},{name:"grain",base:b.MASS,prefixes:M.NONE,value:6479891e-11,offset:0},{name:"dram",base:b.MASS,prefixes:M.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:b.MASS,prefixes:M.NONE,value:.028349523125,offset:0},{name:"poundmass",base:b.MASS,prefixes:M.NONE,value:.45359237,offset:0},{name:"hundredweight",base:b.MASS,prefixes:M.NONE,value:45.359237,offset:0},{name:"stick",base:b.MASS,prefixes:M.NONE,value:.115,offset:0},{name:"gr",base:b.MASS,prefixes:M.NONE,value:6479891e-11,offset:0},{name:"dr",base:b.MASS,prefixes:M.NONE,value:.0017718451953125,offset:0},{name:"oz",base:b.MASS,prefixes:M.NONE,value:.028349523125,offset:0},{name:"lbm",base:b.MASS,prefixes:M.NONE,value:.45359237,offset:0},{name:"cwt",base:b.MASS,prefixes:M.NONE,value:45.359237,offset:0},{name:"s",base:b.TIME,prefixes:M.SHORT,value:1,offset:0},{name:"min",base:b.TIME,prefixes:M.NONE,value:60,offset:0},{name:"h",base:b.TIME,prefixes:M.NONE,value:3600,offset:0},{name:"seconds",base:b.TIME,prefixes:M.LONG,value:1,offset:0},{name:"second",base:b.TIME,prefixes:M.LONG,value:1,offset:0},{name:"sec",base:b.TIME,prefixes:M.LONG,value:1,offset:0},{name:"minutes",base:b.TIME,prefixes:M.NONE,value:60,offset:0},{name:"minute",base:b.TIME,prefixes:M.NONE,value:60,offset:0},{name:"hours",base:b.TIME,prefixes:M.NONE,value:3600,offset:0},{name:"hour",base:b.TIME,prefixes:M.NONE,value:3600,offset:0},{name:"day",base:b.TIME,prefixes:M.NONE,value:86400,offset:0},{name:"days",base:b.TIME,prefixes:M.NONE,value:86400,offset:0},{name:"rad",base:b.ANGLE,prefixes:M.NONE,value:1,offset:0},{name:"deg",base:b.ANGLE,prefixes:M.NONE,value:.017453292519943295,offset:0},{name:"grad",base:b.ANGLE,prefixes:M.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:b.ANGLE,prefixes:M.NONE,value:6.283185307179586,offset:0},{name:"A",base:b.CURRENT,prefixes:M.SHORT,value:1,offset:0},{name:"ampere",base:b.CURRENT,prefixes:M.LONG,value:1,offset:0},{name:"K",base:b.TEMPERATURE,prefixes:M.NONE,value:1,offset:0},{name:"degC",base:b.TEMPERATURE,prefixes:M.NONE,value:1,offset:273.15},{name:"degF",base:b.TEMPERATURE,prefixes:M.NONE,value:1/1.8,offset:459.67},{name:"degR",base:b.TEMPERATURE,prefixes:M.NONE,value:1/1.8,offset:0},{name:"kelvin",base:b.TEMPERATURE,prefixes:M.NONE,value:1,offset:0},{name:"celsius",base:b.TEMPERATURE,prefixes:M.NONE,value:1,offset:273.15},{name:"fahrenheit",base:b.TEMPERATURE,prefixes:M.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:b.TEMPERATURE,prefixes:M.NONE,value:1/1.8,offset:0},{name:"mol",base:b.AMOUNT_OF_SUBSTANCE,prefixes:M.NONE,value:1,offset:0},{name:"mole",base:b.AMOUNT_OF_SUBSTANCE,prefixes:M.NONE,value:1,offset:0},{name:"cd",base:b.LUMINOUS_INTENSITY,prefixes:M.NONE,value:1,offset:0},{name:"candela",base:b.LUMINOUS_INTENSITY,prefixes:M.NONE,value:1,offset:0},{name:"N",base:b.FORCE,prefixes:M.SHORT,value:1,offset:0},{name:"newton",base:b.FORCE,prefixes:M.LONG,value:1,offset:0},{name:"lbf",base:b.FORCE,prefixes:M.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:b.FORCE,prefixes:M.NONE,value:4.4482216152605,offset:0},{name:"b",base:b.BIT,prefixes:M.BINARY_SHORT,value:1,offset:0},{name:"bits",base:b.BIT,prefixes:M.BINARY_LONG,value:1,offset:0},{name:"B",base:b.BIT,prefixes:M.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:b.BIT,prefixes:M.BINARY_LONG,value:8,offset:0}],v.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?h(this.re):0===this.re?1===this.im?"i":-1===this.im?"-i":h(this.im)+"i":this.im>0?1==this.im?h(this.re)+" + i":h(this.re)+" + "+h(this.im)+"i":-1==this.im?h(this.re)+" - i":h(this.re)+" - "+h(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"]},v.E=Math.E,v.LN2=Math.LN2,v.LN10=Math.LN10,v.LOG2E=Math.LOG2E,v.LOG10E=Math.LOG10E,v.PI=Math.PI,v.SQRT1_2=Math.SQRT1_2,v.SQRT2=Math.SQRT2,v.I=new a(0,-1),v.pi=v.PI,v.e=v.E,v.i=v.I,v["in"]=r,r.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:[]},v.sin=o,o.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"]},v.cos=u,u.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"]},v.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"]},v.exp=c,c.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"]},v.sqrt=m,m.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"]},v.abs=p,p.doc={name:"abs",category:"Arithmetic",syntax:["abs(x)"],description:"Compute the absolute value.",examples:["abs(3.5)","abs(-4.2)"],seealso:["sign"]},v.log=N,N.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"]}})(); |