floating-point

Floating Point, how much can I trust less than / greater than comparisons?

别来无恙 提交于 2021-02-18 09:54:40
问题 Let's say I have two floating point numbers, and I want to compare them. If one is greater than the other, the program should take one fork. If the opposite is true, it should take another path. And it should do the same thing, if the value being compared is nudged very slightly in a direction that should still make it compare true. It's a difficult question to phrase, so I wrote this to demonstrate it - float a = random(); float b = random(); // always returns a number (no infinity or NaNs)

Performance of different math functions in x86?

跟風遠走 提交于 2021-02-18 06:31:19
问题 I am writing a 3D collision, and want to know the difference in performance of basic math functions like + - * / sqrt pwr trigonometry like sin cos tan arcsin.. I heard it depends on many other things so I just want to get a rough idea about which one is slower and need to avoid while finding different ways to solve the problem. Also I want to know the order and the magnitude of the difference Thanks Edit: I write in VC++ for x86. But knowledge in other architectures and general picture are

What's wrong with long? Why is subtracting 1 automatically?

大城市里の小女人 提交于 2021-02-17 06:57:10
问题 #include <iostream> #include <math.h> #include <algorithm> using namespace std; int main() { int t, c1, c2, res; string str1, str2; cin >> t; for (int i = 0; i < t; i++) { c1 = c2 = res = 0; cin >> str1 >> str2; c1 = count(str1.begin(), str1.end(), '1'); c2 = count(str2.begin(), str2.end(), '1'); cout << (long)(((pow(10, c1) - 1) / 9) * ((pow(10, c2) - 1) / 9)) << '\n'; } } For input: 1 11111 11111 Output is: 123454321 but, here is the problem, For input: 1 10101 10100 Output is: 1220 Also,

pandas: Dataframe.replace() with regex

和自甴很熟 提交于 2021-02-16 19:12:21
问题 I have a table which looks like this: df_raw = pd.DataFrame(dict(A = pd.Series(['1.00','-1']), B = pd.Series(['1.0','-45.00','-']))) A B 0 1.00 1.0 1 -1 -45.00 2 NaN - I would like to replace '-' to '0.00' using dataframe.replace() but it struggles because of the negative values, '-1', '-45.00'. How can I ignore the negative values and replace only '-' to '0.00' ? my code: df_raw = df_raw.replace(['-','\*'], ['0.00','0.00'], regex=True).astype(np.float64) error code: ValueError: invalid

pandas: Dataframe.replace() with regex

心已入冬 提交于 2021-02-16 19:10:33
问题 I have a table which looks like this: df_raw = pd.DataFrame(dict(A = pd.Series(['1.00','-1']), B = pd.Series(['1.0','-45.00','-']))) A B 0 1.00 1.0 1 -1 -45.00 2 NaN - I would like to replace '-' to '0.00' using dataframe.replace() but it struggles because of the negative values, '-1', '-45.00'. How can I ignore the negative values and replace only '-' to '0.00' ? my code: df_raw = df_raw.replace(['-','\*'], ['0.00','0.00'], regex=True).astype(np.float64) error code: ValueError: invalid

pandas: Dataframe.replace() with regex

房东的猫 提交于 2021-02-16 19:09:48
问题 I have a table which looks like this: df_raw = pd.DataFrame(dict(A = pd.Series(['1.00','-1']), B = pd.Series(['1.0','-45.00','-']))) A B 0 1.00 1.0 1 -1 -45.00 2 NaN - I would like to replace '-' to '0.00' using dataframe.replace() but it struggles because of the negative values, '-1', '-45.00'. How can I ignore the negative values and replace only '-' to '0.00' ? my code: df_raw = df_raw.replace(['-','\*'], ['0.00','0.00'], regex=True).astype(np.float64) error code: ValueError: invalid

Dart Convert IEEE-11073 32-bit FLOAT to a simple double

纵然是瞬间 提交于 2021-02-16 15:34:07
问题 I don't have much experience working with these low level bytes and numbers, so I've come here for help. I'm connecting to a bluetooth thermometer in my Flutter app, and I get an array of numbers formatted like this according to their documentation. I'm attempting to convert these numbers to a plain temperature double, but can't figure out how. This is the "example" the company gives me. However when I get a reading of 98.5 on the thermometer I get a response as an array of [113, 14, 0, 254]

Understanding GCC's floating point constants in assembly listing output

陌路散爱 提交于 2021-02-16 13:45:08
问题 Just out of curiosity, I'm using Compiler Explorer to see the assembly output of some simple C++ codes. Consider the following example int main(void){ double x = -5.3; } Assembly output main: push rbp mov rbp, rsp movsd xmm0, QWORD PTR .LC0[rip] movsd QWORD PTR [rbp-8], xmm0 mov eax, 0 pop rbp ret .LC0: .long 858993459 .long -1072352461 I would like to understand how to use .LC0: .long 858993459 .long -1072352461 to get back my -5.3 . My uninformed guess is that I need to merge the bit

How to *reverse* JavaScripts DataView?

家住魔仙堡 提交于 2021-02-11 17:35:21
问题 I understand this question is oddly phrased, so let me explain with 2 examples. Example 1 The code below turns the series of values [64, 176, 0, 86, 68, 97, 136, 8] into the float 4096.336980910979 . (new DataView(new Uint8Array([64, 176, 0, 86, 68, 97, 136, 8]).buffer)).getFloat64(); /*Output 4096.336980910979*/ How do I reverse it to get the series of values [64, 176, 0, 86, 68, 97, 136, 8] when I input the float 4096.336980910979 ? Example 2: The code below turns the series of values [70,

C++ Adding 1 to very small number?

我怕爱的太早我们不能终老 提交于 2021-02-11 16:56:00
问题 I'm just trying to compute a good sigmoid function in C++ (and efficient). So i have to do something like: 1/(1 + exp(-x)) The problem is, when X becomes big (or even small), the result of 1 + e turns to be 0 or 1 For example, 1 + exp(-30) = 1 But this is incorrect... How can we add very small (or big) numbers easily and efficiently ? Datatype I am using : double Here is the code snippet : double Quaternion::sigmoidReal(double v){ return 1.0 / ( 1.0 + exp(-v) ) ; } Thanks ! 回答1: I think you