JavaScript Woes

 
Quick Nav Menu
  1. JavaScript's lack of mathematical precision
  2. PERL workaround
  3. Related links

The problem is "a lack of precision"

While JavaScript is quickly becoming the lingua franca of the web, this general purpose language contains built-in limitations which restrict its use to simple applications. For example, I recently tried to write a Diffie-Hellman Demo in JavaScript but detected problems during testing which I traced to limited math precision. Check out these comparisons:

JavaScriptMath.pow(7,18) 1628413597910449 correct
Calculator7^181628413597910449  correct
     
JavaScriptMath.pow(7,19)11398895185373144 incorrect
Calculator7^19 11398895185373143correct
      
JavaScriptMath.pow(7,20) 79792266297612000incorrect
Calculator 7^2079792266297612001correct
     
JavaScriptMath.pow(7,21) 558545864083284030incorrect
Calculator 7^21558545864083284007correct

PERL Workaround

Legend:	<sr> = system response
	<ur> = user response

<sr>	$
<ur>	type bigint_demo.pl
	#
	#       title: bigint_demo.pl
	#
	use bigint;             # use bigint after this point
	$x = 7 ** 19;           # x = 7^19
	printf("%s\n",$x);      # "%s" because other formats bomb
<sr>	$
<ur>	perl bigint_demo.pl
<sr>	11398895185373143	! correct
<ur>	$

Related Links


Back to OpenVMS
Back to Home
Neil Rieck
Kitchener - Waterloo - Cambridge, Ontario, Canada.