Sponsored Content
Top Forums Programming Javascript: gamma approximation Post 302876504 by figaro on Monday 25th of November 2013 06:10:57 AM
Old 11-25-2013
Javascript: gamma approximation

Here is some javascript code that implements the Lanczos approximation to the gamma function (http://en.wikipedia.org/wiki/Lanczos_approximation):

Code:
<script type="text/javascript">
// Gamma approximation; coefficients used by the GNU Scientific Library
function gamma(z) {
  var p = [0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7];
  if z < 0.5 {
     return Math.PI / (Math.sin(Math.PI*z) * gamma(1-z));
  } else {
    z -= 1;
    x = p[0];
    for (var i = 0; i < p.length; i++) x += p[i]/(z+i);
    t = z + p.length - 1.5;
    return Math.sqrt(2*Math.PI) * Math.pow(t, z+0.5) * Math.exp(-t) * x;
  }
}

for (var x = 0.1; x < 3; x += 0.1) document.write("x: " + x + " gamma(x): " + gamma(x) + "<br/>");
</script>

This returns an empty page, which usually means there is a syntactical error in the code. In the absence of a proper debugger, can anyone point out where this error might be?

Thank you in advance.
 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

javascript onClick help

I have two radio buttons with corresponding text boxes for input, when one is chosen I am disabling the text box for the other, is there a way to "gray out" the disabled text box using background-color or something? Any help is greatly appreciated, right now my onClick looks like this: ... (1 Reply)
Discussion started by: k@ssidy
1 Replies

2. Shell Programming and Scripting

javascript injection

Please advise a script to get rid of the following code which is infected in a large number of files ( in particular php and html files ) <div id="testws35fdgh"></div> <script language="JavaScript"> var0 = "\x69\x3c\x33\x27\x34\x38\x30\x75\x3b\x34"; var1 =... (20 Replies)
Discussion started by: fed.linuxgossip
20 Replies

3. UNIX and Linux Applications

stopclock coding in javascript.

i have got a problem in this coding.i have got start/pause in the same button.wen i open that page the stopclock runs automatically.wen i click pause it get paused in the frontend textbox bt running in the backend.wen i again click that start itz starting from the time without considering that... (2 Replies)
Discussion started by: VIJI
2 Replies

4. Web Development

Sortable Tables in Javascript

Hi, I am writing a web application using Perl-CgI mostly. I wanted to integrate a table in which I was capable of sorting columns and I don't think this is possible with static HTML code. Can someone help me integrating some javascript code into what I have to acheive the above? Regards,... (6 Replies)
Discussion started by: garric
6 Replies

5. Web Development

Javascript Problems in Opera 10

Ref earlier post: https://www.unix.com/web-programming-web-2-0-mashups/118283-opera-10-0-released-looks-nice.html I have noticed that Google Docs, Speadsheets does not work properly in Opera 10. Anyone else seen the same thing? (1 Reply)
Discussion started by: Neo
1 Replies

6. Programming

Help in javascript

Hi , I wanted to know if its possible to execute a javascript function like this E:- function js1(){ alert ("this is js1"); } function js2(){ alert ("this is js2"); } function js3(){ .... execthisscript(js1); execthisscript(js2); } ... (1 Reply)
Discussion started by: daptal
1 Replies

7. Programming

Need help with Javascript

Hi guys, Ok first, let me explain what I want to do. I'm making a theme for the iphone, and I found a nice wallpaper slideshow script. Here is how it knows which wallpapers to use: <script type="text/javascript"> // SLIDE ROTATION FREQUENCY (in minutes) var slideRotation = 0.4;... (3 Replies)
Discussion started by: kicker75
3 Replies
Math::BigInt::FastCalc(3pm)				 Perl Programmers Reference Guide			       Math::BigInt::FastCalc(3pm)

NAME
Math::BigInt::FastCalc - Math::BigInt::Calc with some XS for more speed SYNOPSIS
Provides support for big integer calculations. Not intended to be used by other modules. Other modules which sport the same functions can also be used to support Math::BigInt, like Math::BigInt::GMP or Math::BigInt::Pari. DESCRIPTION
In order to allow for multiple big integer libraries, Math::BigInt was rewritten to use library modules for core math routines. Any module which follows the same API as this can be used instead by using the following: use Math::BigInt lib => 'libname'; 'libname' is either the long name ('Math::BigInt::Pari'), or only the short version like 'Pari'. To use this library: use Math::BigInt lib => 'FastCalc'; Note that from Math::BigInt v1.76 onwards, FastCalc will be loaded automatically, if possible. STORAGE
FastCalc works exactly like Calc, in stores the numbers in decimal form, chopped into parts. METHODS
The following functions are now implemented in FastCalc.xs: _is_odd _is_even _is_one _is_zero _is_two _is_ten _zero _one _two _ten _acmp _len _inc _dec __strip_zeros _copy LICENSE
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. AUTHORS
Original math code by Mark Biggar, rewritten by Tels <http://bloodgate.com/> in late 2000. Separated from BigInt and shaped API with the help of John Peacock. Fixed, sped-up and enhanced by Tels http://bloodgate.com 2001-2003. Further streamlining (api_version 1 etc.) by Tels 2004-2007. Bug-fixing by Peter John Acklam <pjacklam@online.no> 2010-2011. SEE ALSO
Math::BigInt, Math::BigFloat, Math::BigInt::GMP, Math::BigInt::FastCalc and Math::BigInt::Pari. perl v5.18.2 2014-01-06 Math::BigInt::FastCalc(3pm)
All times are GMT -4. The time now is 09:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy