precision

Square roots by Newton’s method

五迷三道 提交于 2020-02-07 02:36:22
问题 The following Scheme program implements Newton’s method for computing the square root of a number: (import (scheme small)) (define (sqrt x) (define (sqrt-iter guess) (if (good-enough? guess) guess (sqrt-iter (improve guess)))) (define (good-enough? guess) (define tolerance 0.001) (< (abs (- (square guess) x)) tolerance)) (define (improve guess) (if (= guess 0) guess (average guess (/ x guess)))) (define (average x y) (/ (+ x y) 2)) (define initial-guess 1.0) (sqrt-iter initial-guess))

Convert number from float64 to Int64 is incorrect [closed]

折月煮酒 提交于 2020-01-30 13:27:09
问题 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 16 days ago . I try to write a function, the code: package main import ( "encoding/json" "fmt" ) type Test struct { Data map[string]interface{} `json:"data"` } func main() { jsonStr := "{\"data\": {\"id\": 999804707614896129}}" t := &Test{} json.Unmarshal([]byte(jsonStr), t) fmt.Println(int64(t.Data["id"].(float64))) var x

Why max digits with decimal in JavaScript are only 16

可紊 提交于 2020-01-30 11:58:08
问题 I came across this issue a while back when I was testing some HTML forms. The Maximum number of digits in JavaScript Number with a decimal point is only 16 I have tried the following var x = 12345678912345.6789 x is 12345678912345.68 - 16 Digits only var x = 123456789123.6789 x is 123456789123.6789 - 16 Digits only new Number(12345678912345.6789) 12345678912345.68 - 16 Digits only new Number(123456789123.6789) 123456789123.6789 - 16 Digits only if you count the total digits, they are 16. If

Why max digits with decimal in JavaScript are only 16

天涯浪子 提交于 2020-01-30 11:56:05
问题 I came across this issue a while back when I was testing some HTML forms. The Maximum number of digits in JavaScript Number with a decimal point is only 16 I have tried the following var x = 12345678912345.6789 x is 12345678912345.68 - 16 Digits only var x = 123456789123.6789 x is 123456789123.6789 - 16 Digits only new Number(12345678912345.6789) 12345678912345.68 - 16 Digits only new Number(123456789123.6789) 123456789123.6789 - 16 Digits only if you count the total digits, they are 16. If

How to get largest possible precision? (Python - Decimal)

自作多情 提交于 2020-01-30 04:19:10
问题 I'm using the Decimal class for operations that requires precision. I would like to use 'largest possible' precision. With this, I mean as precise as the system on which the program runs can handle. To set a certain precision it's simple: import decimal decimal.getcontext().prec = 123 #123 decimal precision I tried to figure out the maximum precision the 'Decimal' class can compute: print(decimal.MAX_PREC) >> 999999999999999999 So I tried to set the precision to the maximum precision (knowing

Set precision an element in Matlab matrix

房东的猫 提交于 2020-01-25 22:00:58
问题 I want to set precision for all element of a matrix. Below is what I did: >>A A = 0 1.0000 0 0 0 0 -137.0830 0 0 0 0 0 0 0 0 1.0000 0 0 365.5546 0 0 0 0 0 0 0 0 0 0 1.0000 365.5546 0 0 0 0 0 >> vpa(A,2) ans = [ 0, 1.0, 0, 0, 0, 0] [ -144.0, 0, 0, 0, 0, 0] [ 0, 0, 0, 1.0, 0, 0] [ 377.0, 0, 0, 0, 0, 0] [ 0, 0, 0, 0, 0, 1.0] [ 377.0, 0, 0, 0, 0, 0] The result is not my desire, it should be: -137.08, 365.55, 365.55 in the first column. Please help to suggest me how to get it. Thank you so much!

Double in place of Float and Float rounding

做~自己de王妃 提交于 2020-01-25 13:57:32
问题 Edit: This question covers two topics: The efficiency of using in double in place of float Float precision following rounding Is there any reason why I should not always use Java double instead of float? I ask this question because this test code when using floats is failing and not clear why since the only difference is the use of float instead of double. public class BigDecimalTest { @Test public void testDeltaUsingDouble() { //test passes BigDecimal left = new BigDecimal("0.99").setScale(2

PowerShell Start-Process loses precision on number passed as a string to a function

喜你入骨 提交于 2020-01-17 10:23:25
问题 I have some code that edits the registry, so it needs to run as admin. To do this, I start up a new PowerShell process from my running PowerShell script, and pass in part of the registry key path, which happens to be a version number, e.g. "12.0". The function in the new PowerShell process receives the string as "12" though, not "12.0", and so I'm getting errors that it can't find the registry key. I've created a little sample powershell script that reproduces the problem. Here's the snippet:

PHP: format floats with given precision in json_encode() function

时光怂恿深爱的人放手 提交于 2020-01-17 06:45:46
问题 There was my question (initially not so accurate formulated): I need to use PHP floats in JSON string. Code: $obj['val'] = '6.40'; json_encode($obj); is converted to: {"val": "6.40"} It's OK - I have string value '6.40' in PHP and I have string value "6.40" in JSON. The situation is not so good if I need to use floats: $obj['val'] = 6.40; json_encode($obj); is converted to: {"val": 6.4000000000000004} but I need: {"val": 6.40} How can I convert PHP floats to JSON number in 'json_encode' with

Double precision values

心不动则不痛 提交于 2020-01-17 03:45:08
问题 Just a day before I participated in the qualification round of Google Code Jam. This is my first experience of such an online coding contest. It was really fun. There were three problems given of which i was able to solve two. But on one of the problems I was asked to work with values that are really huge. I am a Java guy and I thought I would go for double variable. Unfortunately, the precision of double also was not enough. Moreover, I attended this during the closing stage, I was not