Machine Constants in Javascript?

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jul 2006
Posts: 88
Reputation: DavidB is an unknown quantity at this point 
Solved Threads: 2
DavidB DavidB is offline Offline
Junior Poster in Training

Machine Constants in Javascript?

 
0
  #1
Jun 1st, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,642
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 472
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Machine Constants in Javascript?

 
0
  #2
Jun 3rd, 2007
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:
  1. // Vars.js
  2. var DB_EPSILON = 0.00000000123
  3. var DB_MIN = 0.125

  1. <html>
  2. <head>
  3. <script src="Vars.js"></script>
  4. </head>
  5. <body>
  6. <!-- code -->
  7. </body>
  8. </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
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,210
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 164
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: Machine Constants in Javascript?

 
0
  #3
Jun 5th, 2007
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: 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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC