当前位置:网站首页>Square root cube root
Square root cube root
2022-07-23 12:58:00 【Blue cabuda】
Preface
square root
1. Dichotomy
The code is as follows ( Example ):
double SQRT_Binary(double n)
{
double l = 0, r = n;
if(n<0) l=n,r=0;
while(l<r)
{
double mid = (l + r) / 2;
if(mid * mid > n)
//if(mid*mid*mid)>n Cube root
//if(mid*mid*mid<E||mid*mid*mid>-E) return mid; Less than a certain threshold output
//
r = mid;
else if(mid * mid < n)
l = mid;
else return mid;
}
}
2. Newton's iteration
The code is as follows ( Example ):

double SQRT_Newton(double n)
{
double x0 = n;
double x1;
while(1)
{
//x1 = -(x0 * x0 - n) / (2 * x0) + x0;
x1 = (x0 * x0 + n) / (2 * x0);
//x1=(x0*x0*x0+n)/(3*x0*x0)
double val = x1 * x1 - n;
if(val <= inf && val >= -inf)
return x1;
x0 = x1;
}
return 0;
}
/
边栏推荐
- 简洁描述raft与paxos在设计上的共同点和不同点
- 静态路由配置实例学习记录
- 0 dynamic programming leetcode918. Maximum sum of circular subarrays
- Unity3d+moba+ skill indicator (I)
- Explain the flow control mechanism and congestion control mechanism of TCP in detail
- 学习日记——(路由与交换技术)OSPF协议
- nfs服务部署笔记
- openvpn部署
- 快速解决:Xshell拖不进去文件夹或者软件包的问题
- Unity3d:ugui, UI and special effect particle level, bakemesh above 2018.2, particles between two images and in Scrollview
猜你喜欢

帧中继网配置实例学习记录

学习日记——(路由与交换技术)动态路由(rip协议)和静态路由

FTP实验及概述

静态路由配置实例学习记录

jenkins用到的插件

Gameframework: package resources, publish packages with the app, package and generate folder instructions, upload resources to the server, download resources, gamefreamworklist DAT and gameframeworkve

深度优先找出图中顶点U到顶点V的所有简单路径
![Build FRPC client in NAS [super brainless]](/img/02/bc150ab6cec73b9142d0e3c3532417.png)
Build FRPC client in NAS [super brainless]

C custom queue set

MySQL performance optimization, index optimization
随机推荐
0 dynamic planning leetcode1024. Video splicing
Hcip ---- relevant knowledge points of GRE protocol, mGRE environment and OSPF Protocol
帧中继网配置实例学习记录
关于搭建Hybrid App所需要的基础技术一文
nfs服务部署笔记
Routing extension configuration of OSPF and rip
Understand the article frankly and get the HTTP protocol cache
How to write a web page with a common text editor
Openssl自行签证流程概述
Learning diary - (routing and switching technology) layer 3 switch
C: stack stack source code, array stack, chain stack
C#输出斐波那契数列
学习日记——(路由与交换技术)动态路由(rip协议)和静态路由
Explanation of websocket protocol
学习日记——(路由与交换技术)ACL访问控制列表
平方根立方根
Homework of the fifth week
Unity3d: vector calculation, AOE graph intersection
Unity3d:assetbundle simulation loading, synchronous loading, asynchronous loading, dependent package loading, automatic labeling, AB browser, incremental packaging
PDF在线预览,pdf.js的使用