Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
I thought I found a way to compute PI, but I actually just found a super shitty way to print a variable..
const precision = 1000000
// convert degree to radians
function rad(degree){
return degree * (Math.PI/180);
}
function calculatePI(){
// [x, y]
// take first point on start of unic circle
const point1 = [Math.cos(0) , Math.sin(0)];
// take second point at 0.001 degree
const point2 = [Math.cos(rad(1/precision)), Math.sin(rad(1/precision))];
// Estimate 0.001 degree of circle
const dist = Math.sqrt((point2[0] - point1[0] ) ** 2 + (point2[1] - point1[1]) ** 2);
// Calculate full circle
const perimeter = dist * precision * 180;
return perimeter;
}
console.log(calculatePI());
devrant