pi

Leibniz formula for pi - Java [closed]

岁酱吖の 提交于 2019-12-12 06:58:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . So, Leibniz's formula for pi is pi/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9... I can't figure out how to use this formula in Java. I just need some help on how to incorporate the second part into it. I know I need a loop and I need the have a divisor variable, and that it needs plus 2 each time. Thanks for any help. 回答1:

how to get image orientation to rotate 270 degrees (swift3)

99封情书 提交于 2019-12-12 02:34:07
问题 Right now this code will only rotate my image 90 degrees. I can not figure out how to rotate it 270 degrees. transform = transform.rotated(by: CGFloat(Double.pi)) 回答1: Start with some basic math. 360° = 2π. 180° = π. 90° = π/2. 270° = 3π/2. This means your posted code is rotating 180 degrees. Use Double.pi/2 for 90° and 3*Double.pi/2 for 270°. 来源: https://stackoverflow.com/questions/43619944/how-to-get-image-orientation-to-rotate-270-degrees-swift3

C++ Chudnovsky Formula for Pi

断了今生、忘了曾经 提交于 2019-12-11 09:35:25
问题 I am trying to make a C++ application calculate pi for me. I have tried to implement the Chudnovsky formula with no luck. Here is my code: #include <iostream> #include <cmath> long fac(long num) { if (num == 1) return 1; return fac(num - 1) * num; } int main() { using namespace std; double pi; for (long k = 0; k < 10; k++) { pi += (pow(-1, k) * fac(6 * k) * (13591409 + (545140134 * k))) / (fac(3 * k) * pow(fac(k), 3) * pow(640320, 3 * k + 3/2)); } pi *= 12; cout << 1 / pi << endl; system(

.NET C# Double equivalent System.Numerics.BigInteger

点点圈 提交于 2019-12-11 07:35:30
问题 I'm am currently writing a program that calculates the digits of pi, and I have a problem. After three iterations the number of correct digits exceeds the memory available in a double. I heard of the System.Numerics.BigInteger type (in System.Numerics.dll), but I need to use floating point numbers. I do not understand the algorithm well enough to use integers. It would be great if a version of the BigInteger exists which supports a decimal point. Below I have put my C# code: var a = 1.0; var

Defining value of PI

妖精的绣舞 提交于 2019-12-11 06:56:42
问题 I am working on a new project and I am trying to write the cleanest, easiest to read and hopefully, most efficient, code I can. I need to use PI but apparently it isn't defined in math.h. So I read about doing this: const double PI = atan(1.0)*4 But I get this error: A function call cannot appear in a constant-expression Any ideas on why? How can I get PI as a constant? Also, please, I am trying to learn as much as I can with this project, so it would be great if you could also explain why

Using a long double or just a double for calculating pi?

ⅰ亾dé卋堺 提交于 2019-12-11 02:26:01
问题 I'm calculating pi using a long winded formula. I'm trying to get more familiar with floating point numbers etc. I have a working program that uses doubles. The problem with my code is: If I use a double, pi is only accurate to the 7th decimal place. I can't get it to be any more accurate. If I use a long double, pi is accurate up to the 9th decimal place however the code takes much longer to run. If I check for precision for less than 0.00000001 using a long double, pi returns a value of 9

Calculating PI using Monte Carlo method gives imprecise answer

落爺英雄遲暮 提交于 2019-12-10 18:39:15
问题 I am trying to calculate PI using Monte Carlo method. My code gives the result 3.000 no matter how big MAXLEN is. After debugging it many times, I couldn't get what I'm doing wrong. #include <stdio.h> #include <stdlib.h> #define sqr2(x) ((x)*(x)) #define frand() ((double) rand() / (RAND_MAX)) #define MAXLEN 1000 int circumscribed(int radius){ float xcoord = frand(); float ycoord = frand(); float coord = sqr2(xcoord) + sqr2(ycoord); if(coord <= radius) return 1; return -1; } int main() { int i

Is java.lang.Math.PI equal to GCC's M_PI?

北城余情 提交于 2019-12-10 13:32:17
问题 I am coding several reference algorithms in both Java and C/C++. Some of these algorithms use π. I would like for the two implementations of each algorithm to produce identical results, without rounding differently. One way to do this that has worked consistently so far is to use a custom-defined pi constant which is exactly the same in both languages, such as 3.14159. However, it strikes me as silly to define pi when there are already high-precision constants defined in both the Java and GCC

解决Raspberry Pi不识别RTL8188eu无线网卡芯片的问题

霸气de小男生 提交于 2019-12-10 02:15:22
最近在折腾Raspberry Pi,当时也没留意,看在价格的份上,买了Mercury的 水星网络 MW150US 超小型150M无线USB网卡。可是悲剧的是用iwconfig并认不到这款无线网卡 但是用lsusb的话可以看到MW150US用的正是RTL8188eu的芯片,在网络上搜索了一下,终于找到解决方案 1. 首先要下载编译安装最新的linux内核,具体可以参考 http://www.raspberrypi.org/documentation/linux/kernel/building.md 2. 然后继续下载编译安装RTL8188eu的驱动 $ git clone --depth 1 https://github.com/lwfinger/rtl8188eu $ cd rtl8188eu $ make && make install 3. 这时候再用iwconfig就可以看到wlan0了 4. 然后最好是reboot一下,这时候再激活无线网卡,扫描无线网络 $ ifconfig wlan0 up $ iwlist wlan0 scan 5. 最后就是配置无线网络用户名密码,这里就不详述了 来源: oschina 链接: https://my.oschina.net/u/1431631/blog/316669

raspberry pi无线网卡配置

非 Y 不嫁゛ 提交于 2019-12-10 02:01:50
raspberry pi的操作系统采用最新的raspbian操作系统,该操作系统是基于Debian 7.3,内核版本为3.10.25+。USB wifi适配器采用的是TP-LINK TL-WN725N。将TL-WN725N插入到raspberry pi的USB口后,在串口终端使用命令lsmod可以看到8192cu的内核模块被加载(说明该无线网卡驱动已经驱起来了),与此同时在串口终端使用命令ifconfig可以看到wlan0的相关信息。我们要做的就是修改/etc/network/interface文件,修改成功后保存,最后执行/etc/init.d/networking restart即可。下面是我的/etc/network/interface配置文件。 auto lo iface lo inet loopback iface eth0 inet dhcp auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid "myssid" wpa-psk "mypsk" 其中: auto wlan0 :说明系统启动时自动启动wlan0; allow-hotplug wlan0:允许热插拔wlan0; iface wlan0 inet dhcp:对wlan0网口使用dhcp方式获取IP地址; wpa-ssid "myssid"