I write numerical routines for students of science and engineering (although they are freely available for use by anybody else as well) and am wondering how to properly use machine constants in a JavaScript program, or if they are even applicable.
For example, say I am writing a program in C++ that numerically computes the roots of the following equation:
exp(-0.7x) + sin(3x) - 1.2x + 0.3546 = 0
A root-finding routine should be able to compute roots to within the machine epsilon. In C++, this value is specified by the language: DBL_EPSILON. C++ also specifies the smallest and largest values that can be held by a float or double variable.
However, how does this convert to JavaScript? Since a Javascript program runs in a web browser, and I don't know what kind of computer will run the program, and JavaScript does not have corresponding predefined values for these quantities, how can I implement my own version of these constants so that my programs compute results to as much accuracy as allowed on the computer running the web browser?
My first draft is to simply copy over the literal constants from C++:
FLT_MIN: 1.17549435082229e-038
FLT_MAX: 3.40282346638529e+038
DBL_EPSILON: 2.2204460492503131e-16
I am also willing to write small code blocks that could compute these values for each machine on which the program is run. That way, a supercomputer might compute results to a higher accuracy than an old, low-level, PC.
BUT, I don't know if such a routine would actually reach the computer, in which case, I would be wasting my time.
Anybody here know how to compute and use (in Javascript) values that correspond to machine constants in a compiled language?
Is it worth my time to write small programs in Javascript that compute DBL_EPSILON, FLT_MIN, FLT_MIN, etc. for use in numerical routines?
Or am I better off simply assigning literal constants that come straight from C++ on a standard Windows PC?