Javascript has a very small math function list. However there is no
reason that this list can not be extended greatly. Speed is not an
issue, unless you nest complicated calculations several levels deep. In
that case you need much more ram than a PC has to store functions
calculated in loops so that you do not have to recalculate every time
you cycle through the nest of loops. Using a HD for storage to extend
ram is much too slow for many applications.
Some functions such as hyperbolic ones are easy to add, since they are
just simple combinations of the built in javascript math functions. I
have found a few examples on the web such as Bessel functions. I found
far fewer javascript math functions than I expected on Google searches.
Thus I have had to write several functions of my own.
See http://www.cwdjr.net/math/I0L0andI1L1.html for an example of two
"functions from hell" that are very difficult to evaluate. Fortunately
there are Fortran programs that can be used as a starting point. I was
able to modify the Fortran programs to work on javascript. I have used
these functions for technical applications in the past.
The page is set up to reject the NN 4 series, because it will not
support some of the script needed such as .toExponential(n) and
to.Fixed(n)for writing output in exponential or fixed format. I was
amazed that even the old MSNTV(former WebTV) settop box, that no
longer is being made, will even support these output formats. I wonder
about IE4. If it will not support these output formats, I can easly
block it by checking for document.getElementById.
The code works properly on the latest versions of IE6, MSN9, Firefox,
Mozilla, Netscape, and Opera. I am not selling anything, so for a
special interest page such as this, I see no need to support older
browsers.
The advantage of doing math with javascript is that it is so portable.
You can do it anywhere you can use a computer, or you can do it on your
own local computer offline. There are several math programs for PCs
that will do very much more than you can hope to do with javascript.
Unfortunately the program I would like costs about US$ 1800. Also there
are versions you can install on a server, but these also are expensive. 17 3436
"I was
amazed that even the old MSNTV(former WebTV) settop box, that no
longer is being made, will even support these output formats."
Admit it, you are an idiot.
First you wanted custom math function for javascript.
Then you complain about (see line 1)
========================
Show me your money.
I have no time for leisure consumers of anything.
Pay your dues, that is 50 years of tellings others what to do.

SUMMARY:
Do nothing, just go away.
Your "US" kind is not so kind after all.
It is considered the overbearing curse of the world.
On 22/06/2005 06:02, cw******@yahoo.com wrote: Javascript has a very small math function list. However there is no reason that this list can not be extended greatly.
Have you considered the fact that a large selection of such functions
would go largely unused, and therefore be a waste of time and resources
to implement and expose?
In specialised applications, a host is free to extend what objects and
methods are implemented, but as far as browsers are concerned, there is
no benefit in adding lots of methods to the Math object.
[snip]
The page is set up to reject the NN 4 series, because it will not support some of the script needed such as .toExponential(n) and to.Fixed(n)for writing output in exponential or fixed format.
Implementations of both methods are bugridden in some hosts.
I wonder about IE4. If it will not support these output formats, I can easly block it by checking for document.getElementById.
You would be better off blocking browsers based on what they do, or do
not, support, not on unrelated features. See
<URL:http://www.jibbering.com/faq/#FAQ4_26> and its links.
[snip]
Mike

Michael Winter
Replace ".invalid" with ".uk" to reply by email.
Michael Winter replied: Javascript has a very small math function list. However there is no reason that this list can not be extended greatly.
Have you considered the fact that a large selection of such functions
would go largely unused, and therefore be a waste of time and resources
to implement and expose?
In specialised applications, a host is free to extend what objects and
methods are implemented, but as far as browsers are concerned, there is
no benefit in adding lots of methods to the Math object.
[snip]
The page is set up to reject the NN 4 series, because it will not support some of the script needed such as .toExponential(n) and to.Fixed(n)for writing output in exponential or fixed format.
Implementations of both methods are bugridden in some hosts.
I wonder about IE4. If it will not support these output formats, I can easly block it by checking for document.getElementById.
You would be better off blocking browsers based on what they do, or do
not, support, not on unrelated features. See
<URL:http://www.jibbering.com/faq/#*FAQ4_26> and its links.
There is every benefit to adding at least 20 more standard browser Math
objects. The standard hyperbolic and other functions that are used by
even high school students are very easy to add. This should cost very
little to do. Not everyone is interested in commercial business web
pages. The ability of javascript to do meaningful calculations on
browsers has been very much neglected. I have demonstrated that even a
rather complex function could be added without undue effort. The
methods for evaluation of most standard math functions were developed
long before there were even computers to do the math in a short time.
It is just a part of standard university math.
If what you mean is that implementation of .toExponential and .toFixed
has bugs in some hosts is that there are problems on some servers set
up in certain ways, it is time to change your server if the problem can
not be corrected. I had to do nothing special on the Unix (Apache)
server I have my 2 domains on that is owned by a large international
hosting company that can provide you with either Unix and Microsoft
servers that you can configure in a huge number of ways. Of course
exponential notation long has been standard in the physical sciences.
I saw your FAQs long ago. If you look at my code, you will see that I
blocked NN4 by checking for support of document .layers. Since even
Netscape quit layers support with their 6 browser, using
document.layers is good enough. I did mention checking for
document.getElementById support to block IE4, if that ever seems
needed. This of course would block earlier IE browsers. If you wanted
to include the old MSNTV, you can be certain you have one of these
beasts by checking navigator.appCodeName. This returns "bowser" in
contrast to "Mozilla" you get on most modern browsers. Detection of a
specific Browser sometimes is necessary when a certain browser has a
bug. For example, Opera has a bug for some script used for controlling
media players. You need to use a different code to play the media on
Opera. Navigator.appName is usless because Opera can be set to spoof
several other browsers here. Old MSNTV boxes spoofed IE4, etc. However,
for Opera, you can scan the user agent for the string "Opera". This
seems to be accurate for all recent browsers I have checked. Thus you
need to start detecting what a browser can do, but in rare cases you
may need to know what browsers you are dealing with  especially to get
around bugs. You have to test new versions of browsers as they are
released to make sure nothing has been changed, or if the bug has gone
away and now needs no correction.
I now have another page for an application of the functions in my first
post at http://www.cwdjr.net/math/cylinderAbsorption.html . The results
are in good agreement with the origanal calculations made many years
ago on an IBM 370 using Fortran 4, Hlevel, the results of which were
published in an internatonal peer reviewed journal.
On 22/06/2005 22:14, cw******@yahoo.com wrote:
Please learn to post properly. Michael Winter replied:
[OP:] Javascript has a very small math function list. [...]
Have you considered the fact that a large selection of such functions would go largely unused, and therefore be a waste of time and resources to implement and expose?
There is every benefit to adding at least 20 more standard browser Math objects.
Perhaps you should read that again: those methods would go largely
unused and wouldn't be worth the effort of implementation in most cases,
/especially/ if they are easily created in user code.
In my opinion, a Web scripting language should focus on the features
necessary to script Web documents. The core language shouldn't be
bloated with unnecessary features. Host specific implementations can add
what they like, but such extensions shouldn't become a required feature.
Anyway, what exactly is the point of posting this rant here? What do you
expect us to do about it?
[snip] Implementations of both [Number.prototype.toExponential and toFixed] are bugridden in some hosts.
If what you mean is that implementation of .toExponential and .toFixed has bugs in some hosts is that there are problems on some servers set up in certain ways, it is time to change your server if the problem can not be corrected.
I couldn't recall which hosts were affected at the time of writing, so I
decided to be nonspecific. It would seem that JScript is the main concern.
[snip] You would be better off blocking browsers based on what they do, or do not, support, not on unrelated features. See <URL:http://www.jibbering.com/faq/#*FAQ4_26> and its links.
I saw your FAQs long ago. If you look at my code, you will see that I blocked NN4 by checking for support of document .layers.
So? Omniweb also implements the layers collection. Others might, too.
Browser detection is flawed, plain and simple.
[snip]
Detection of a specific Browser sometimes is necessary when a certain browser has a bug.
Not necessarily. Many bugs can be preempted by developing a test case
that catches erroneous behaviour.
[snip]
You have to test new versions of browsers as they are released to make sure nothing has been changed, or if the bug has gone away and now needs no correction.
Which is why feature detection is far superior: it automatically
responds to that situation.
[snip]
Mike

Michael Winter
Replace ".invalid" with ".uk" to reply by email.
JRS: In article <11**********************@z14g2000cwz.googlegroups .com>
, dated Tue, 21 Jun 2005 22:02:57, seen in news:comp.lang.javascript, cw******@yahoo.com <cw******@yahoo.com> posted : The page is set up to reject the NN 4 series, because it will not support some of the script needed such as .toExponential(n) and to.Fixed(n)for writing output in exponential or fixed format.
It should not be difficult to emulate the part of their functionality
that you probably need; for example, if a Number is multiplied by 1E150
and converted to String, it will be exponential; then split off the
exponent, subtract 150 from it, and restore. Untested.
For fixed format, read the newsgroup FAQ.

© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/jsindex.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
JRS: In article <O8******************@text.news.blueyonder.co.uk >,
dated Wed, 22 Jun 2005 23:05:18, seen in news:comp.lang.javascript,
Michael Winter <m.******@blueyonder.co.invalid> posted : Perhaps you should read that again: those methods would go largely unused and wouldn't be worth the effort of implementation in most cases, /especially/ if they are easily created in user code.
In my opinion, a Web scripting language should focus on the features necessary to script Web documents. The core language shouldn't be bloated with unnecessary features. Host specific implementations can add what they like, but such extensions shouldn't become a required feature.
ISTM that you may be overestimating the OP's ability to express himself
accurately in English; he or she is likely to be a foreigner, after all,
probably not even European.
You are right in saying that the core language should not be extended
with obscure maths functions. However, the set provided is not large,
and the code needed to implement a few more would not be large; the
burden would be mainly documentational. By "a few" I mean maybe to
include all six prime trig functions, their inverses, and the
corresponding hyperbolics; factorial, combination, permutation, and not
a lot more.
It would be of use (though not necessarily worthwhile) to have a
professionalquality library of more advanced maths (and other)
functions, assembled in such a manner that those needed for a particular
task could be copied for use as Methods or Functions.
But, to be trustworthy, they'd need to be maintained and hosted by a
reputable academicclass institution; not by some anonymous self
assessed whizzkid.

© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/jsindex.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
.. There is every benefit to adding at least 20 more standard browser Math objects. The standard hyperbolic and other functions that are used by even high school students are very easy to add. This should cost very little to do.
adding hyperbolic functions to the current set would actually be an
exellent exercise for students to implement.
it is not the job of language designers to provide all the specific
tools programmers will ever need, it it their job to provide the most
basic set of tools upon which programmers can build.
anyway, the formula for hyperbolic transcendentals are easy to find and
just as easy to implement:
Math.sinh = function(x)
{
with(Math)
return (exp(x)  exp(x))/2;
}
Math.asinh = function(x)
{
with(Math)
return log(x + sqrt(1 + x * x));
}
Math.cosh = function(x)
{
with(Math)
return (exp(x) + exp(x))/2;
}
Math.acosh = function(x)
{
with(Math)
return log(x + sqrt(x * x  1));
}
Math.tanh = function(x)
{
with(Math)
return sinh(x)/cosh(x);
}
Math.atanh = function(x)
{
with(Math)
return 0.5 * log((1 + x)/(1  x));
}
Math.coth = function(x)
{
with(Math)
return 1/tanh(x);
}
Math.acoth = function(x)
{
with(Math)
return 0.5 * log((x + 1)/(x  1));
}
Math.sech = function(x)
{
with(Math)
return 1/cosh(x);
}
Math.asech = function(x)
{
with(Math)
return log((1 + sqrt(1  x * x))/ x );
}
Math.csch = function(x)
{
with(Math)
return 1/sinh(x);
}
Math.acsch = function(x)
{
with(Math)
return log((1 + (x < 0 ? 1 : 1) * sqrt(1 + x * x))/ x );
// if i understood the domains correctly
}
Math.versinh = function(x)
{
with(Math)
return 1  cosh(x);
}
Math.haversinh = function(x)
{
with(Math)
return (1  cosh(x))/2;
// or (sinh(x/2))*(sinh(x/2));
// or versinh(x)/2;
}
Division by zero in JS is "Infinity"...
The "telling" feature of every added hyberbolic function above is
"with(Math)" (everything you *need* is already there) and all that is
used is exp, log, sqrt, and/or one of the other methods being defined.
There is really nothing here complicated enough to merit having the
functions predefined in the Math object.
fox wrote: . There is every benefit to adding at least 20 more standard browser Math objects. The standard hyperbolic and other functions that are used by even high school students are very easy to add. This should cost very little to do.
adding hyperbolic functions to the current set would actually be an exellent exercise for students to implement.
it is not the job of language designers to provide all the specific tools programmers will ever need, it it their job to provide the most basic set of tools upon which programmers can build.
anyway, the formula for hyperbolic transcendentals are easy to find and just as easy to implement:
I guess people such as myself with a physical science background
consider much more math basic than a businessman, for example. Anyway
it would not be difficult to add many more math functions to basic math
and would not require enough additional memory to matter these days. It
is a matter of convenience for the less complicated functions.
I have about 36 additional functions ranging from the trivial to the
complex now. I found some on the web, I modified others from Fortran
programs, and I wrote some of my own. At least for a limited time, you
may view them at my site. Credit is given when the code comes from the
web, so you can check the sites from which I obtained the code. Not all
of these functions have been well tested, and there could have been
mistakes in the copy to the web page. This is a work in progress.
Please note that all of these functions are used as is. Do not use
Math. before them. They work either within a with (Math){blah blah}
section or without one. If I ever get time, I am going to write the
basic JS math functions without the .Math so you just have to use
sin(x), etc without anything else. From my background, I can not see
why the Math. was included. It is just a bother, any anyone with a high
school education should know what the basic math functions mean and not
use them for something else. Perhaps they considered that elementary
school students might write script before they had much math.
See http://www.cwdjr.net/mathExtra/ , which contains 4 pages. The
external javascript file containing all of the functions can be linked
to, at least for a while, so it is easy to check some of the functions
without downloading the JS external file. There also is a text file of
the scripts. Another brief text file lists the functions and has a
brief comment. A html feedback form is provided in case you wish to
send me a comment. cw******@yahoo.com wrote: fox wrote:
.
There is every benefit to adding at least 20 more standard browser Math objects. The standard hyperbolic and other functions that are used by even high school students are very easy to add. This should cost very little to do. adding hyperbolic functions to the current set would actually be an exellent exercise for students to implement.
it is not the job of language designers to provide all the specific tools programmers will ever need, it it their job to provide the most basic set of tools upon which programmers can build.
anyway, the formula for hyperbolic transcendentals are easy to find and just as easy to implement:
I guess people such as myself with a physical science background consider much more math basic than a businessman, for example.
Anyway it would not be difficult to add many more math functions to basic math and would not require enough additional memory to matter these days. It is a matter of convenience for the less complicated functions.
I have about 36 additional functions ranging from the trivial to the complex now. I found some on the web, I modified others from Fortran programs, and I wrote some of my own. At least for a limited time, you may view them at my site. Credit is given when the code comes from the web, so you can check the sites from which I obtained the code. Not all of these functions have been well tested, and there could have been mistakes in the copy to the web page. This is a work in progress. Please note that all of these functions are used as is. Do not use Math. before them. They work either within a with (Math){blah blah} section or without one. If I ever get time, I am going to write the basic JS math functions without the .Math so you just have to use sin(x), etc without anything else. From my background, I can not see why the Math. was included. It is just a bother, any anyone with a high school education should know what the basic math functions mean and not use them for something else. Perhaps they considered that elementary school students might write script before they had much math.
See http://www.cwdjr.net/mathExtra/ , which contains 4 pages. The external javascript file containing all of the functions can be linked to, at least for a while, so it is easy to check some of the functions without downloading the JS external file. There also is a text file of the scripts. Another brief text file lists the functions and has a brief comment. A html feedback form is provided in case you wish to send me a comment.
Thank you for these  I am particularly interested in the Bessel
functions...
On Thu, 23 Jun 2005 21:27:12 0500, fox <sp******@fxmahoney.com>
wrote: . There is every benefit to adding at least 20 more standard browser Math objects. The standard hyperbolic and other functions that are used by even high school students are very easy to add. This should cost very little to do. adding hyperbolic functions to the current set would actually be an exellent exercise for students to implement.
it is not the job of language designers to provide all the specific tools programmers will ever need, it it their job to provide the most basic set of tools upon which programmers can build.
anyway, the formula for hyperbolic transcendentals are easy to find and just as easy to implement:
SNIP The "telling" feature of every added hyberbolic function above is "with(Math)" (everything you *need* is already there) and all that is used is exp, log, sqrt, and/or one of the other methods being defined. There is really nothing here complicated enough to merit having the functions predefined in the Math object.
I am afraid you have just illustrated the point that John Stockton
made  that it isn't as easy as that. Your functions will fail
interestingly and undetectably in many cases  some could end up
returning the result of taking the difference of two numbers very
close in value, for example. The loss of precision would make the
results meaningless. And of course, some may return the result of
dividing a very large number by a very small number  again, with
results depending on the behaviour of the floating point engine. Of
course, the divide by zero error you mention will be caught, but other
situations which result in disastrous loss of precision won't be.
The textbook formulae are in most cases designed to illustrate the
properties and derivation of the function, and are not a practical
means of computing it reliably. Practical implementations have to take
into account the problems of working with digital arithmetic, provide
proper exception handling and guaranteed precision. That is why John
Stockton suggested that creating and maintaining such a library was a
task for a Mathematics or Computer Science group, not for an
individual. I wouldn't take it on, and I am used to complex
trigonometrical calculations.
Paul
JRS: In article <8d********************************@4ax.com>, dated
Fri, 24 Jun 2005 09:22:17, seen in news:comp.lang.javascript, Paul
Cooper <pa*********@Nobasspam.ac.uk> posted : I am afraid you have just illustrated the point that John Stockton made  that it isn't as easy as that. Your functions will fail interestingly and undetectably in many cases  some could end up returning the result of taking the difference of two numbers very close in value, for example. The loss of precision would make the results meaningless. And of course, some may return the result of dividing a very large number by a very small number  again, with results depending on the behaviour of the floating point engine. Of course, the divide by zero error you mention will be caught, but other situations which result in disastrous loss of precision won't be.
The textbook formulae are in most cases designed to illustrate the properties and derivation of the function, and are not a practical means of computing it reliably. Practical implementations have to take into account the problems of working with digital arithmetic, provide proper exception handling and guaranteed precision. That is why John Stockton suggested that creating and maintaining such a library was a task for a Mathematics or Computer Science group, not for an individual. I wouldn't take it on, and I am used to complex trigonometrical calculations.
Indeed. To illustrate : this expression is from the Help of several
versions of a widelysold compiler family (not necessarily the latest
versions) :
ArcCos(x) = ArcTan (sqrt (1sqr (x)) /x)
It is trigonometrically correct.
However, ArcTan always returns an angle within 90 to +90, whereas a
positive argument for ArcCos should return one of two values in that
range and a negative argument for ArcCos should return one of two values
in the other half of the circle.
They forgot that every positive real number has two square roots of
opposite sign, and that it is always necessary to choose the appropriate
one; whereas in that language sqrt, like Math.sqrt, always gives a non
negative result.
The expression is computationally incorrect; other trigonometrical
expressions are also computationally correct.
I vaguely recall that ATAN2 may be better than ATAN as a primitive.
It could be possible to extend the Math object with bolton native code;
that would potentially be better, by allowing direct use of the FPU.
I can't recall whether I said this before, but I lived for a year at #54
of the road by which you work, if you are housed in SPRI.

© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/jsindex.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Paul Cooper wrote:
Practical implementations have to take into account the problems of working with digital arithmetic, provide proper exception handling and guaranteed precision.
There are many good programs written in Fortran and C++ as well as many
long discarded languages for evaluating the more common math functions.
These have built in checks and warning messages in many cases.These
programs often are fairly easy to adapt to JS. However one does not
always want the highest precision. In fact, if one is calculating math
functions within a deep nest, you need to use the least precision
possible for the problem to speed up very long calculations. This of
course requires a detailed analysis of the system at hand. Mathematica
5.1, for example, will allow you to select the number of places needed
for a function output.
If you are wanting to do math on the computer, and not the web, of
course you need to add C++, Fortran, or other higher level language
support, or you may be able to get by with Mathematica or something of
the sort. Unfortunately Mathematica 5.1 costs about $US1800 new,
although Amazon is now having a sale in the $1500 range. This is too
high a price for many indivaduals, although reduced rates are available
for students. There also is an expensive version of Mathematica you can
put on your server. However, here you must be very careful if you do
not have use of an entire server. Some math operations can use a huge
amount of server capacity. On a shared server, there often are
restrictions on the maximum percentage of capacity you can use at any
time. Exceeding this limit can result in huge bills or disconnection
until you resolve the problem. At least this is the way my domain host
works.
There is a free program, Dataplot, available from the NIST, the US
government standards organization, known as the NBS(National Bureau of
Standards) until fairly recently. See http://www.itl.nist.gov/div898/software/dataplot/ . This is written in
Fortran, but compiled and ready to use on many different PC platforms
without adding a Fortran compiler. This program will evaluate a huge
number of even very uncommon functions. It will plot and display these
functions, or results for equations using functions. It will accept
input data and curve fit and do statistical analysis. The range of
types of statistical analysis is huge. I have found this program very
useful. It also can be installed on a server. Dataplot may not be as
fancy and do as many things as some of the expensive commercial
programs, but it does many things as well as many people need. It is
nice to have around when you want to check math you are doing using JS
for the web. I also believe the program is free to foreigners,
including the British, even though they are not US tax payers who
support the government organizations :). I have had a little contact
with the NIST in the past and have been impressed by the quality of
most of their work. Unfortunately they have a very restricted budget
these days. Also the Nobel committee has been well impressed with the
quility of some of their work.
Paul Cooper wrote: On Thu, 23 Jun 2005 21:27:12 0500, fox <sp******@fxmahoney.com> wrote:
.
There is every benefit to adding at least 20 more standard browser Math objects. The standard hyperbolic and other functions that are used by even high school students are very easy to add. This should cost very little to do. adding hyperbolic functions to the current set would actually be an exellent exercise for students to implement.
it is not the job of language designers to provide all the specific tools programmers will ever need, it it their job to provide the most basic set of tools upon which programmers can build.
anyway, the formula for hyperbolic transcendentals are easy to find and just as easy to implement:
SNIP
The "telling" feature of every added hyberbolic function above is "with(Math)" (everything you *need* is already there) and all that is used is exp, log, sqrt, and/or one of the other methods being defined. There is really nothing here complicated enough to merit having the functions predefined in the Math object. I am afraid you have just illustrated the point that John Stockton made  that it isn't as easy as that.
Actually, 1) I didn't *illustrate* ANYTHING of the sort, and 2) it IS as
easy as that... do you think that if these functions were implemented in
the native math package, they would be implemented differently than
this? JavaScript wasn't designed for mathmaticians or scientists... it
is a "general purpose" *scripting* language...
Besides, the *point* of my original response was *not* the functions
themselves, but the method of extending the Math package and how easily
accomplished it actually is. If practical implementations are important
to you, why don't you submit them here... instead of *just talking about
it*.
Your functions will fail interestingly and undetectably in many cases  some could end up returning the result of taking the difference of two numbers very close in value, for example. The loss of precision would make the results meaningless. And of course, some may return the result of dividing a very large number by a very small number  again, with results depending on the behaviour of the floating point engine. Of course, the divide by zero error you mention will be caught, but other situations which result in disastrous loss of precision won't be.
Show me... then show me how any of it is different than what already
exists in the Math package. Show me in terms of a "normal" program that
somebody would need for an application, and not some kind of contrived
"special case" designed to break it.
The JS FP "engine" is quite robust... 64 bit ieee754 (if ecma compliant)
.... reports NaNs and Infinities... gradual underflow... fairly unbreakable.
BTW  what is a "disastrous loss of precision?" I've been programming
over 23 years now, and I've never heard of this... The textbook formulae are in most cases designed to illustrate the properties and derivation of the function, and are not a practical means of computing it reliably.
I would contend that such derived functions (the "longer versions" being
"proofs") *are* a means of computing them reliably. The definitions did
not state "approximately equal to"  they are as stated.
Practically speaking, from a programmer's point of view: the "extended"
Math functions/methods use already nativelyprovided functions and very
little overhead...i.e.: they won't slow you down much.
I don't think there are very many people around who would be patient
enough for a scripting language like JavaScript to evaluate Taylor's
Series Expansions and the like to achieve a "precise" value of any of
these functions. (and considering these series tend to "oscillate"
across a limit as they approach it, stopping the evaluation at
arbitrarily shorter terms to save time and/or execution overhead could
render the result MORE imprecise than using exponentials and logs.)
Practical implementations have to take into account the problems of working with digital arithmetic, provide proper exception handling and guaranteed precision. That is why John Stockton suggested that creating and maintaining such a library was a task for a Mathematics or Computer Science group, not for an
this is almost hysterical... talk about overkill. What would they call it?
Applied Numerics And Logic group?
"Guaranteed precision" (whatever that is) is not a feature of the Math
package... never has been. Considering the precision we do have in Math,
if you implement precision handling within the methods themselves, you
take it out of the hands of the programmers who would not ordinarily
require it and slowing down operations for everybody across the board.
Programmers are responsible for handling ranges and precisions in and
out of the basic functions... this sort of thing does not belong inside
general purpose functions.
If you need to use a *browser* for "guaranteed precision", use Netscape
and load the java.math package for arbitraryprecision math:
if(navigator.appName.indexOf("Netscape") != 1)
// doomed to fail if spoofed
// also, java support in v6 was "interrupted"
// so this may or may not work in NN6
{
var BD = java.math.BigDecimal;
var somedecimal_1 =
new BD("12340.0000000000000000000000000000001");
var somedecimal_2 =
new BD("12340.0000000000000000000000000000003");
var sum = somedecimal_1.add(somedecimal_2);
}
else
var sum = "You need a Netscape browser to use this";
alert(sum);
// result: 24680.0000000000000000000000000000004 exactly
// works in NN4 and NN7/8  btw: that's 36 significant digits
// more than twice what you get in javascript
// and can have arbitrarily greater significant digits
use strings to instantiate the BigDecimal, otherwise you run into the
same binary > decimal conversion problems.
roll your own ... ...knock yourself out...
(it will *not* be a "practical" use of your time... I can guarantee with
remarkable precision)
On Fri, 24 Jun 2005 22:54:32 +0100, Dr John Stockton I can't recall whether I said this before, but I lived for a year at #54 of the road by which you work, if you are housed in SPRI.
I used to work at SPRI from 19791988 after which I moved to BAS. BAS
is located on Madingley Road, right next to the M11.
Best wishes
Paul
JRS: In article <d9**********@news.datasync.com>, dated Sun, 26 Jun
2005 03:12:29, seen in news:comp.lang.javascript, fox
<sp******@fxmahoney.com> posted : Paul Cooper wrote:
I am afraid you have just illustrated the point that John Stockton made  that it isn't as easy as that.
Actually, 1) I didn't *illustrate* ANYTHING of the sort, and 2) it IS as easy as that... do you think that if these functions were implemented in the native math package, they would be implemented differently than this?
That depends on the competence of the implementer, and on the degree of
effort used. For example, Math.cosh would most easily, I expect, be
provided by use of Math.exp itself; but it would more effectively be
provided by directly calling the machine's native exp function.
JavaScript wasn't designed for mathmaticians or scientists... it is a "general purpose" *scripting* language...
ISTM that it was more thrown together than designed, in contrast to,
say, Wirth's Pascal.
Functions provided as part of the system should be implemented to full
machine accuracy over the full range; the system provider cannot
completely tell what the system may be used for, though he should
understand the commoner cases.
Remember that over 99% of javascripters will not recall cosh other than
as an instrument of assault; those who use it will largely be doing
technical applications, and will want correctness.
Besides, the *point* of my original response was *not* the functions themselves, but the method of extending the Math package and how easily accomplished it actually is. If practical implementations are important to you, why don't you submit them here... instead of *just talking about it*.
He truly recognises the degree of effort and skill needed to do the job
well; you do not, or do not care.
BTW  what is a "disastrous loss of precision?" I've been programming over 23 years now, and I've never heard of this...
The selftaught generally have wide areas of lamentable ignorance; the
clever ones recognise this.
I would contend that such derived functions (the "longer versions" being "proofs") *are* a means of computing them reliably. The definitions did not state "approximately equal to"  they are as stated.
In infiniteprecision mathematics, and where speed cannot matter, yes;
in actual implementation, no.
Consider sinh(x), defined as (exp(x)exp(x)/2. Calculated that way, it
has a 45% error at x=1E16, and is 0 at x = 1E17.
A competent implementation would substitute sinh(x) = x for sufficiently
small x, where sufficiently small seems to be reached at the 1E5..1E6
region, or more likely would use a method not requiring exp itself; in
particular, for x>=0 it would never return sinh(x)<x.
I don't think there are very many people around who would be patient enough for a scripting language like JavaScript to evaluate Taylor's Series Expansions and the like to achieve a "precise" value of any of these functions. (and considering these series tend to "oscillate" across a limit as they approach it, stopping the evaluation at arbitrarily shorter terms to save time and/or execution overhead could render the result MORE imprecise than using exponentials and logs.)
But have you the depth of understanding required for your thought to be
of any value? Practical implementations have to take into account the problems of working with digital arithmetic, provide proper exception handling and guaranteed precision. That is why John Stockton suggested that creating and maintaining such a library was a task for a Mathematics or Computer Science group, not for an
this is almost hysterical... talk about overkill. What would they call it?
Applied Numerics And Logic group?
DAMTP? not quite.

© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/jsindex.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
JRS: In article <95********************************@4ax.com>, dated
Mon, 27 Jun 2005 11:29:41, seen in news:comp.lang.javascript, Paul
Cooper <pa*********@Nobasspam.ac.uk> posted : On Fri, 24 Jun 2005 22:54:32 +0100, Dr John Stockton I can't recall whether I said this before, but I lived for a year at #54 of the road by which you work, if you are housed in SPRI.
I used to work at SPRI from 19791988 after which I moved to BAS. BAS is located on Madingley Road, right next to the M11.
After my time.
Regards,

© John Stockton, Surrey, UK. *@merlyn.demon.co.uk / ??*********@physics.org ©
Web <URL:http://www.merlyn.demon.co.uk/>  FAQish topics, acronyms, & links.
Correct <= 4line sig. separator as above, a line precisely " " (SoRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)
Dr John Stockton wrote: JRS: In article <d9**********@news.datasync.com>, dated Sun, 26 Jun
That depends on the competence of the implementer, and on the degree of effort used...
He truly recognises the degree of effort and skill needed to do the job well; you do not, or do not care.
The selftaught generally have wide areas of lamentable ignorance; the clever ones recognise this.
A competent implementation ...
But have you the depth of understanding required for your thought to be of any value?
You are entitled to your opinion. Somewhat harsh... but maybe you're right.
I have a "little" program I wrote about five or six years ago and I'm
have a section of code I could use your help with (actually not entirely
offtopic...quite a lot of "extended math functions" technically
reapplied to the Number object though)...it's *right up your alley.* It
involves physics and perhaps you're right, a mere programmer is not
capable of the understanding required. [haven't had the time to revisit
it since so the gui I planned never materialized it's very bare bones
 not "cluttered".]
It should be really simple to read... after all, I wrote it *for* myself.
If you find yourself wondering: I attached the methods to the Number
object so I could easily follow along with Meeus' book: Astronomical
Algorithms. Extra PI precision (in places) because this was supposed to
be ported to Java later. Originally started out with "classic" orbital
elements then converted to vsop.
The main Object is "Planet()" [index page] instantiated from "handleClick"
For my application, I do not need better precision than to the nearest
arcminute (although arcseconds would definitely be preferable... but
hey! this is me we're talking about) compared to the ephemerides of JPL
or the like for "apparent geocentric" coordinates and the output is in
terms of Zodiacal position (longitude  just converting degrees to
something familiar).
....I'm having a little problem with Pluto (up to +/ 5 arcmins off), and
perhaps you could see where my errors are: http://fxmahoney.com/demo/astro/
Pluto specific routines are at the bottom of the vsop.js file (before
the moon routines).
[recommend Courier New (8pt, if possible) used as font for viewing source]
I really would appreciate your help. You *are* the doctor. This discussion thread is closed Replies have been disabled for this discussion. Similar topics
1 post
views
Thread by Robert Mark Bram 
last post: by

2 posts
views
Thread by Henri Sivonen 
last post: by

15 posts
views
Thread by Ingmar 
last post: by

5 posts
views
Thread by Ark 
last post: by

110 posts
views
Thread by Gregory Pietsch 
last post: by

11 posts
views
Thread by Sambo 
last post: by

7 posts
views
Thread by Mark Healey 
last post: by
 
5 posts
views
Thread by aguirre.adolfo 
last post: by
          