precision

How do I extract a JSON list into a CSV in command line using JQ?

拜拜、爱过 提交于 2020-08-08 06:39:19
问题 I have the following JSON data: % cat test2 {"day":"2020-07-15","map": {"a":"ask","b":"bid","t":"timestamp"},"msLatency":52,"pair":"EUR/USD","status":"success","ticks":[ {"b":1.14105,"a":1.14106,"x":48,"t":1594771200000}, {"b":1.14105,"a":1.14106,"x":48,"t":1594771201000}, {"b":1.14103,"a":1.14104,"x":48,"t":1594771202000}, {"b":1.141,"a":1.1413,"x":48,"t":1594771203000}, {"b":1.14103,"a":1.14104,"x":48,"t":1594771205000}, {"b":1.14094,"a":1.14095,"x":48,"t":1594778803000}],"type":"forex"}

what is meant by 'Most C system provide for logically infinite floating values'?

ⅰ亾dé卋堺 提交于 2020-07-09 03:00:33
问题 Initially I declared variables x and y as type int: #include<stdio.h> int main(){ int x, y = 0 ; x = 1 / y; printf("%d", x); return 0; } Program crashed (for obvious reasons). Now I declared variables x and y as double: #include<stdio.h> int main(){ double x, y = 0 ; x = 1 / y; printf("%d", x); return 0; } But Output: 0. (why?) Then I changed %d to %f in printf: #include<stdio.h> int main(){ double x, y = 0 ; x = 1 / y; printf("%f", x); return 0; } Output: 1.#INF00 I don't understand what is

what is meant by 'Most C system provide for logically infinite floating values'?

℡╲_俬逩灬. 提交于 2020-07-09 02:58:05
问题 Initially I declared variables x and y as type int: #include<stdio.h> int main(){ int x, y = 0 ; x = 1 / y; printf("%d", x); return 0; } Program crashed (for obvious reasons). Now I declared variables x and y as double: #include<stdio.h> int main(){ double x, y = 0 ; x = 1 / y; printf("%d", x); return 0; } But Output: 0. (why?) Then I changed %d to %f in printf: #include<stdio.h> int main(){ double x, y = 0 ; x = 1 / y; printf("%f", x); return 0; } Output: 1.#INF00 I don't understand what is

Why is 0.29999999999999998 converted to 0.3?

和自甴很熟 提交于 2020-06-26 07:56:55
问题 How does it work internally? How does it decide to convert 0.29999999999999998 to 0.3 , even though 0.3 cannot be represented in binary? Here are some more example: scala> 0.29999999999999998 res1: Double = 0.3 scala> 0.29999999999999997 res2: Double = 0.3 scala> 0.29999999999999996 res3: Double = 0.29999999999999993 scala> 0.29999999999999995 res4: Double = 0.29999999999999993 回答1: There are two conversions involved. First 0.29999999999999998 is converted to 0

Why is 0.29999999999999998 converted to 0.3?

☆樱花仙子☆ 提交于 2020-06-26 07:56:16
问题 How does it work internally? How does it decide to convert 0.29999999999999998 to 0.3 , even though 0.3 cannot be represented in binary? Here are some more example: scala> 0.29999999999999998 res1: Double = 0.3 scala> 0.29999999999999997 res2: Double = 0.3 scala> 0.29999999999999996 res3: Double = 0.29999999999999993 scala> 0.29999999999999995 res4: Double = 0.29999999999999993 回答1: There are two conversions involved. First 0.29999999999999998 is converted to 0

%precision 2 on Python

本小妞迷上赌 提交于 2020-06-25 03:56:48
问题 If I have this piece of code: import csv %precision 2 with open('blah.csv') as csvfile: blah = list(csv.DictReader(csvfile)) What does it means the %precision 2 line? 回答1: This is an IPython magic. It controls how floats display: >>> 1.2345 1.2345 >>> %precision 2 '%.2f' >>> 1.2345 1.23 Documented here. Note : It suggests your script was intended to be executed within an IPython runtime (such as a notebook). In a regular Python interpreter that will be a syntax error. 回答2: This is to set a

Why is the output different in both cases comparing floats

本秂侑毒 提交于 2020-06-17 08:03:32
问题 PYTHON PROGRAM : a = 0.2 if a == 0.2: print('*') OUTPUT : * C PROGRAM : #include <stdio.h> int main(void) { float a = 0.2; if(a == 0.2) { puts("*"); } } OUTPUT : Why is the output different in both cases? Is there a difference between the working of == operator? 回答1: It is because the types float and double have different width reserved for the mantissa. The type double can represent a floating number more precisely. In this case that matters as 0.2 can't be represented exactly and has a very

What is the difference between np.float64 and np.double?

会有一股神秘感。 提交于 2020-05-26 19:30:47
问题 I tried running the following code to find out the difference between float64 and double in numpy . The result is interesting as type double takes almost double the time compared with time taken for multiplication with float64 . Need some light on this. import time import numpy as np datalen = 100000 times = 10000 a = np.random.rand(datalen) b = np.random.rand(datalen) da = np.float64(a) db = np.float64(a) dda = np.double(a) ddb = np.double(b) tic = time.time() for k in range(times): dd = dda

Hamming numbers and double precision

可紊 提交于 2020-05-15 02:09:43
问题 I was playing around with generating Hamming numbers in Haskell, trying to improve on the obvious (pardon the naming of the functions) mergeUniq :: Ord a => [a] -> [a] -> [a] mergeUniq (x:xs) (y:ys) = case x `compare` y of EQ -> x : mergeUniq xs ys LT -> x : mergeUniq xs (y:ys) GT -> y : mergeUniq (x:xs) ys powers :: [Integer] powers = 1 : expand 2 `mergeUniq` expand 3 `mergeUniq` expand 5 where expand factor = (factor *) <$> powers I noticed that I can avoid the (slower) arbitrary precision