English 中文(简体)
当出现时,如何运作
原标题:Floating points, when does it appear, how it works

就我所知,浮标可以准确反映14个数字。

So let s say we have

a = 564214623154
b = 54252

and we multiply this c=a*b and it should be 30609771735350808 but when compiled it shows me 3.0609771735351E+16 So as I understand it should lose some precision but when I divide c by a c/a I get 564214623154 exact result without any precision lost

另外一个例子让我们说:

c = 30609771735350808 
d = 30609761111111111

e=c-d应为10624239697,但在汇编后,显示我为1062423969696,因此失去精确度

So is precision lost only when I subtract or add two numbers?

If it matters I use php

最佳回答

It is possible to lose precision with multiplication and division also. PHP and JavaScript store numbers in IEEE-754 format with 52 bits of mantissa and 11 bits of exponent. Some integers are represented exactly and some are not.

Let s try these:

In Real Math (generated with Ruby):

45345657434523 * 9347287748322342 / 74387422372 = 5697991604786167788

PHP和Javad

45345657434523 * 9347287748322342 / 74387422372 = 5697991604786168000

因此,我们也在重复和分裂方面失去准确性。

EDIT:在重新审视被占领土上的问题时,似乎这不是一个很大的答案,因为结果包含超过15位精准数字。 如果问题的意图是,每组数字在15位精度或更低的数位数上乘和分立,那么最终结果往往会保持相当的精确度(如果你不过度流入或流入)。 因此,您可以乘以<代码>1.25E35* 2.5E7,并精确到3.125e+42。 这是因为PHP和Java的成文将主要增加大量数字,并增加支出。 然而,如果您的英文译文是英文版,则您的两种数值是1.25E35 + 2.5E7 = 1.25E35。 这一权利,你们增加了2 500万,不会改变! 这是因为,正如《任择议定书》所述,你只获得14或15名精准数字。 人工添加这两个数值如下:12000000000000000000000000000 + 25000。 14-15位数从左边开始计算,你可以 pick。

Bottom line is precision problems are more likely to arise with addition and subtraction. Good to be aware of.

问题回答

In your first case you lose no precision, PHP is just formatting the larger number as a float. (Internally the number is kept as a float.) Try this go get the "precise" output:

$a = 564214623154;
$b = 54252;
$c = $a * $b;
printf("%u, %u
", $c, $c/$a);

其次,在<代码>c* d的情况下,您的两人个人人数已超过标准电子计算系统-64轨道浮动能力(即53比值,但至少需要55比值),因此,如果你储存这些数字,就已经失去精确性。

添加/减让期间失去精确性的问题称为“取消”: 您所花费的所有储存都被取消了。 最后,你没有足够准确的比照来填补这些 man。 C est la vie.

想象你会再次坐在月球上,你对兄弟们在联合王国Worcester的耳光长度进行了两次测量。 比较这两种测量,是因为你要求储存大量精确度。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签