Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.postgresql > #884

Re: calculating pi [Re: php and big data and predictive modelling...]

Newsgroups comp.databases.postgresql
Date 2019-12-28 09:40 -0800
References (3 earlier) <5e0717d0$0$10269$e4fe514c@news.xs4all.nl> <f8d31fcf-af88-457c-8b78-a456b3f19654@googlegroups.com> <5e073d4a$0$10273$e4fe514c@news.xs4all.nl> <6b2f2a6b-bddf-4398-8ba8-4aa5b4ea6e46@googlegroups.com> <5e077cca$0$10261$e4fe514c@news.xs4all.nl>
Message-ID <a29d8b40-5288-4a95-b243-75e0d756a072@googlegroups.com> (permalink)
Subject Re: calculating pi [Re: php and big data and predictive modelling...]
From robamman2019@gmail.com

Show all headers | View raw


The BigNumber library is available at : https://github.com/MikeMcl/bignumber.js/ .
I modified this code a little bit.
For example with width 5000 square The Pi came out 3.1415....
It took about 1 minute.

findingpi.html:

<html>
<head>
<meta charset="utf-8">
<title>Calculating pi</title>
<script src='bignumber/bignumber.js'></script>
<style>
#pivalue {
    border: 1px solid green;
	margin: 5px;
	height: 200px;
	width: 500px;
	overflow-x: auto;
	overflow-wrap: break-word;
}
</style>
</head>
<body>

<form onsubmit="findnumber(); return false;">
<h1>
<p>Pi(The Circle circumference divided with it's diameter)</p>
<p>Pi can be calculated with a circle inside a square. The Pi estimated value is the following: (Circle area)*4/(Square area).
</p>
<p>Please enter square width <input style="width: 200px; height: 40px; font-size: 30px;" type="text" id="squarew"></input></p>
<p><button type="submit" style="width: 200px; height: 40px; font-size: 30px;">Calculate pi</button></p>
<p id="pivalue"></p>
<p>For estonians: Soovitan kasutada translate.google.com-i kui inglise keelt ei mõika.</p>

</h1>

</form>
<script>
var incircle=new BigNumber(0);
var area=new BigNumber(0);
function pointisincircle(xx0,yy0,xx,yy,radius) {
	  var aaa1=xx0.minus(xx);
	  var aaa2=(yy0).minus(yy);
	  var isin=(aaa1.multipliedBy(aaa1).plus(aaa2.multipliedBy(aaa2))).isLessThanOrEqualTo(radius.multipliedBy(radius));
      return isin;
}
function findnumber() {
    incircle=new BigNumber(0);
    area=new BigNumber(0);
    
	var squarew=new BigNumber(document.getElementById("squarew").value);
	//document.getElementById("pivalue").innerHTML
	//alert(squarew.valueOf());
	area=squarew.multipliedBy(squarew);
    var xmax=new BigNumber(squarew);
    var ymax=new BigNumber(squarew);
	//alert(xmax.valueOf());
	var radius=new BigNumber(squarew.dividedBy(2));
    var x0=new BigNumber(squarew).dividedBy(2);
    var y0=new BigNumber(squarew).dividedBy(2);
	var x=new BigNumber(0);
	var y=new BigNumber(0);
	var run2=true;
	while(true) {
	      if(x.isEqualTo(xmax)) break;
		  while(run2) {
		        if(y.isEqualTo(ymax)) run2=false;
				if(run2) {
					y=y.plus(new BigNumber(1));
				         	
				} else {
					y=new BigNumber(0);
				}
				if(pointisincircle(x0,y0,x,y,radius)) {
					incircle=incircle.plus(1);
				}
		  }
		  run2=true;
		  x=x.plus(1);
	}
	var pivalue=incircle.multipliedBy(4).dividedBy(area);
	//alert("In circle: "+incircle+" Area: "+area+" Pi value: "+pivalue);
	document.getElementById("pivalue").innerHTML=pivalue;
}
</script>
</body>
</html>

Back to comp.databases.postgresql | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: calculating pi [Re: php and big data and predictive modelling...] robamman2019@gmail.com - 2019-12-28 02:22 -0800
  Re: calculating pi [Re: php and big data and predictive modelling...] robamman2019@gmail.com - 2019-12-28 04:55 -0800
    Re: calculating pi [Re: php and big data and predictive modelling...] robamman2019@gmail.com - 2019-12-28 08:30 -0800
    Re: calculating pi [Re: php and big data and predictive modelling...] robamman2019@gmail.com - 2019-12-28 09:40 -0800
      Re: calculating pi [Re: php and big data and predictive modelling...] robamman2019@gmail.com - 2019-12-29 04:15 -0800

csiph-web