Php: BCMath

bc是Binary Calculator的缩写。bc*函数的参数都是操作数加上一个可选的 [int scale],比如string bcadd(string $left_operand, string $right_operand[, int $scale]),如果scale没有提供,就用bcscale的缺省值。这里大数直接用一个由0-9组成的string表示,计算结果返回的也是一个 string。

bcadd — 将两个高精度数字相加

  string bcadd(string left operand, string right operand [, int scale]);

bccomp — 比较两个高精度数字,返回-1, 0, 1

  int bccomp(string left operand, string right operand [, int scale]);

bcdiv — 将两个高精度数字相除

  string bcdiv(string left operand, string right operand [, int scale]);

bcmod — 求高精度数字余数

  string bcmod(string left operand, string modulus);

bcmul — 将两个高精度数字相乘

  string bcmul(string left operand, string right operand [, int scale]);

bcpow — 求高精度数字乘方

  string bcpow(string x, string y [, int scale]);

bcpowmod — 求高精度数字乘方求模,数论里非常常用

  string bcpowmod ( string x, string y, string modulus [, int scale]);

bcscale — 配置默认小数点位数,相当于就是Linux bc中的”scale=”

  string bcscale(int scale);

bcsqrt — 求高精度数字平方根

  string bcsqrt(string operand [, int scale]);

bcsub — 将两个高精度数字相减

  string bcsub(string left operand, string right operand [, int scale]);

可以参考手册去查这些函数的应用。

bcmath的安装
bcmath这个扩展在php的压缩包中都是有的,需要重新编译一下才能够支持;
cd php-5.2.7/ext/bcmath
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install (make 可以得到so路径)
so路径拷贝到 extension路径
vim php.ini
extension=bcmath.so
重启apach

PHP code?

/*bcsub 函数说明
此函数将二个高精确度的数字相减,传入二个字符串,以左边的 (left operand) 减去右边的 (right operand) 值。scale 是一个可有可无的选项,表示返回值的小数点后所需的位数。*/
//下面的代码我是保证了小数点一位数字
$aa=bcsub(134.7,52.5,1);
echo $aa;//exit;
$bb=bcsub($aa,82.2,1);
echo $bb;//exit;

php关于精准计算的模块 BCMath的更多相关文章

  1. Python科学计算—numpy模块总结(1)

    作为一个本科学数学专业,目前研究非线性物理领域的研究僧.用什么软件进行纯科学计算好,Fortran永远是第一位的:matlab虽然很强大,可以很容易的处理大量的大矩阵,但是求解我们的模型(有时可能是几 ...

  2. Python科学计算包模块的安装(ubuntu)

    Python的科学计算包设计到C语言代码的编译,采用pip的方式安装会出现错误. 一种简单的方式是采用的集成包,具体的步骤参考:https://www.continuum.io/downloads#_ ...

  3. zipline风险指标计算 (empyrical模块)

    概述 量化中,我们经常会遇到各种量化指标的计算,对于zipline来说,也会对这部分计算进行处理,由于指标计算的通用性比较强,所以,zipline单独封装了 empyrical 这个模块,可以处理类似 ...

  4. Python 科学计算涉及模块

    模块1.数据基础 numpy 模块2.数值运算 scipy 模块3.符号运算 sympy 模块4.图形绘制 matplotlib

  5. 数据分析计算xgboost模块

    一.安装xgboost方法 摘要:之前为了安装xgboost,少不了进入各种坑,但最终安装成功了!首先, 准备的工作:,下载mingw64,链接https://pan.baidu.com/s/1i5C ...

  6. MSP430精准配置高速串口波特率的方法

    引言     在实际项目大批量生产调试设备时,笔者发现同样版本的程序在不同设备上运行时效果不一致,一部分设备串口通信正常,另外一部分串口通信不正常.通过示波器对多个设备的串口波特率及系统时钟频率测试, ...

  7. 数字,字符串,time模块,文本进度条

    数字和字符串 数字类型 整形 整数, 1/2/3/12/2019 整形用来描述什么, 身高/年龄/体重 age = 18 height = 180 浮点型 浮点数,小数 salary = 10 pri ...

  8. Python科学计算发行版—Anaconda

    Python是一种强大的编程语言,其提供了很多用于科学计算的模块,常见的包括numpy.scipy和matplotlib.要利用Python进行科学计算,就需要一一安装所需的模块,而这些模块可能又依赖 ...

  9. php浮点数计算问题

    如果用php的+-*/计算浮点数的时候,可能会遇到一些计算结果错误的问题,比如echo intval( 0.58*100 );会打印57,而不是58,这个其实是计算机底层二进制无法精确表示浮点数的一个 ...

随机推荐

  1. disablescroll

    页面的设置 disablescroll:true(需要配合设置 enablePullDownRefresh:false ) 可以实现页面上下不能滑动 另一种实现方法: 设置页面的根元素 绝对定位, p ...

  2. tabbar 设置样式

    app.json配置文件中,使用时需要把注释删除,配置文件不支持备注 tabbar:{ color:'#fff',//字体颜色  需要时HexColor,设置成red 无法识别,下方颜色设置同理 se ...

  3. C# 使用WebClient时,在多网卡时,指定IP发送Web请求

    需要定义一个类,重写GetWebRequest,在方法内,指定IP地址 public class MyWebClient : WebClient { private IPAddress ipAddre ...

  4. Ubuntu 图形处理软件

    sudo add-apt-repository ppa:dhor/myway sudo apt-get update sudo apt-get install photivo

  5. Ubuntu 下编译Android 源代码

    1.配置JDK 1.6 或者1.7(看情况配置,有的Android版本不能在1.7下运行) 2.配置环境:终端:(CTRL+ALT+T) $ sudo apt-get install git gnup ...

  6. 取消IE增强的安全配置

    在window server里用ie各种信任添加很麻烦 可以通过如下方式取消IE增强设置: 如,在Server2008中,点击快速启动栏里面的服务器管理器图标,进入服务器管理器.选择配置 IE ESC ...

  7. Eclipse 安装Maven插件

    这个好: http://www.iteye.com/topic/1123225 其他: 1先安装subeclipse插件就是svn svn - http://subclipse.tigris.org/ ...

  8. E20180525-hm

    sensitive adj. 敏感的; 感觉的; [仪] 灵敏的; 易受影响的; lookup v. 查找; 查表; speedy  adj. 快的,迅速的; 敏捷的 marshal  vt. 整理, ...

  9. 洛谷 - P1072 Hankson - 的趣味题 - 质因数分解

    https://www.luogu.org/problemnew/show/P1072 一开始看了一看居然还想放弃了的. 把 \(x,a_0,a_1,b_0,b_1\) 质因数分解. 例如 \(x=p ...

  10. Weekly Contest 111-------->942. DI String Match

    Given a string S that only contains "I" (increase) or "D" (decrease), let N = S. ...