| | |
Machine Constants in Javascript?
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2006
Posts: 88
Reputation:
Solved Threads: 2
I am presently translating some code from C++ to Javascript and it involves quite a few floating point calculations. The program uses several built-in machine constants to help it quantify and limit computer round-off error. For example, it includes the constants DBL_MIN and DBL_EPSILON from the <cfloat> library within C++.
I am now wondering: does Javascript offer these constants as built-in values too? I suppose I could calculate them myself, by brute force, but if these values are already available, it would help me keep the Javascript version shorter.
Does Javascript provide built-in, comparable values for DBL_MIN and DBL_EPSILON? (If so, how do I access them?)
Regards.
David
I am now wondering: does Javascript offer these constants as built-in values too? I suppose I could calculate them myself, by brute force, but if these values are already available, it would help me keep the Javascript version shorter.
Does Javascript provide built-in, comparable values for DBL_MIN and DBL_EPSILON? (If so, how do I access them?)
Regards.
David
You can always peek into the header files of the compiler you are using to find out the value of those in-built constants and put the same in a JS file and include that file.
Something like:
Something like:
javascript Syntax (Toggle Plain Text)
// Vars.js var DB_EPSILON = 0.00000000123 var DB_MIN = 0.125
javascript Syntax (Toggle Plain Text)
<html> <head> <script src="Vars.js"></script> </head> <body> <!-- code --> </body> </html>
Last edited by ~s.o.s~; Jun 3rd, 2007 at 1:53 pm.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
If you want to know the actual minimum value of the smallest value the current running JavaScript can actually use, it will tell you.
Use:
JS provides the following constants:
The smallest positive value which can be stored. It is close to 5E-324
The largest positive value which can be stored. It is close to 1.79E+308
Returns the internal representation for negative infinity
Returns the internal representation for positive infinity
Returns the natural base.
Returns the natural log of 10.
Returns the natural log of 2.
Returns the common log of the natural base.
Returns the binary-base log of the natural base.
Returns the value of pi.
Returns the square root of one half.
Returns the sqiare root of 2.
Use:
Number.MIN_VALUE JS provides the following constants:
Number.MIN_VALUE:The smallest positive value which can be stored. It is close to 5E-324
Number.MAX_VALUE:The largest positive value which can be stored. It is close to 1.79E+308
Number.NEGATIVE_INFINITY:Returns the internal representation for negative infinity
Number.POSITIVE_INFINITY:Returns the internal representation for positive infinity
Math.E:Returns the natural base.
Math.LN10:Returns the natural log of 10.
Math.LN2:Returns the natural log of 2.
Math.LOG10E:Returns the common log of the natural base.
Math.LOG2E:Returns the binary-base log of the natural base.
Math.PI:Returns the value of pi.
Math.SQRT1_2:Returns the square root of one half.
Math.SQRT2:Returns the sqiare root of 2.
Last edited by MidiMagic; Jun 5th, 2007 at 5:04 pm. Reason: too fat
Daylight-saving time uses more gasoline
![]() |
Similar Threads
- Writing a javascript function (JavaScript / DHTML / AJAX)
- transfer double array from asp to javascript (ASP.NET)
- Using Javascript code in ASP.NET (JavaScript / DHTML / AJAX)
- Links won't open: Javascript related. (Web Browsers)
- Javascript:Void (Null) (Windows NT / 2000 / XP)
- Page Cannot Be Displayed & javascript:doNetDetect() Errors (Viruses, Spyware and other Nasties)
- Unable to run javascript despite correct settings (Web Browsers)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: javascript and iframes
- Next Thread: js calculator
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxcode ajaxhelp animate api automatically beta boarder box bug calendar captchaformproblem card checkbox child class column cookies createrange() css cursor dependent disablefirebug dom download dropdown editor element engine error events explorer ext file firehose flash form forms game google gwt html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump math matrixcaptcha microsoft mimic mp3 mysql object onmouseoutdivproblem onreadystatechange parent passing pdf php player post problem progressbar rated rating regex runtime scroll search select session shopping size sql star stars stretch text textarea twitter validation w3c web website window windowofwords windowsxp wysiwyg xml xspf \n






