nan

acos(1) returns NAN in some conditions

Deadly 提交于 2019-12-10 13:09:50
问题 Here's my code: <?php $lat1 = 35.697959; $lat2 = 35.697959; $lon1 = 139.707085; $lon2 = 139.707085; $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); var_dump($dist); // returns 1 $dist = acos($dist); var_dump($dist); // returns NAN As you can see from the comments, $dist is equal to 1 after the calculation, but when I apply acos() it returns NAN . If I try to replicate it manually, it works just fine:

What is the “char-sequence” argument to NaN generating functions for?

≡放荡痞女 提交于 2019-12-10 12:51:37
问题 Aside from the NAN macro, C99 has two ways to generate a NaN value for a floating point number, the nanf(const char *tagp) function and strtof("NAN(char-sequence)") . Both of these methods of generating a NaN take an optional string argument (*tagp in nanf() and the char-sequence in the strtof method). What exactly does this string argument do? I haven't been able to find any concrete examples of how you'd use it. From cppreference.com we have: The call nan("string") is equivalent to the call

Pandas replace nan with mean value for a given grouping

懵懂的女人 提交于 2019-12-10 10:09:56
问题 I have a large dataset of the form: period_id gic_subindustry_id operating_mgn_fym5 operating_mgn_fym4 317 201509 25101010 13.348150 11.745965 682 201509 20101010 10.228725 10.473917 903 201509 20101010 NaN 17.700966 1057 201509 50101010 27.858305 28.378040 1222 201509 25502020 15.598956 11.658813 2195 201508 25502020 27.688324 22.969760 2439 201508 45202020 NaN 27.145216 2946 201508 45102020 17.956425 18.327724 In practice, I have thousands of values for each year going back 25 years, and

Assigning using += gives NaN in javascript

拥有回忆 提交于 2019-12-10 10:06:13
问题 Assignment a number to an attribute using the += operator gives me NaN in JavaScript. This code works as expected: > var result = {}; undefined > result['value'] = 10; 10 > result['value'] += 10; 20 But here we get NaN : > var test = {}; undefined > test['value'] += 10; NaN Why does JavaScript behave like this? How can I get this to work without initializing result['value'] = 0 ? 回答1: You can't add a number to undefined in JavaScript. If you don't want to initialize the number, you need to

How to have all platform compiler output the same string for NaN?

梦想的初衷 提交于 2019-12-10 03:07:23
问题 Consider this code snippet: #include <iostream> #include <string> #include <limits> int main() { std::cout << std::numeric_limits<double>::quiet_NaN(); } When compiled with Visual Studio 2010, output is 1.#QNAN . When compiled with g++, output is nan . Note that Visual Studio 2015 outputs "nan". However, I need both to produce the same output. What's the most simple way to do that? I tried to override operator<< for double but I feel like that's not the right way to do. Can string to be used

How to overcome the NaN and continue the calculation in Javascript - Negative value for radicand of sqrt

无人久伴 提交于 2019-12-10 03:07:09
问题 I have set up a js / three.js program for calculating cylinders by only two given values. The only calculation that is quite difficult happens when volume and surface are given. From both values I need to calculate the radius or the height. To recall the formulas: Volume V = π·r²·h Surface A = 2·π·r·(r+h) If you do the math, you will get the cubic formula: 0 = r^3 + A/(-2*pi)*r + V/pi which I honestly could not solve, so I used wolframalpha that gives this result for the radius r: Note: There

Exporting ints with missing values to csv in Pandas

倾然丶 夕夏残阳落幕 提交于 2019-12-10 01:31:25
问题 When saving a Pandas DataFrame to csv, some integers are getting converted in floats. It happens where a column of floats has missing values ( np.nan ). Is there a simple way to avoid it? (Especially in an automatic way - I often deal with many columns of various data types.) For example import pandas as pd import numpy as np df = pd.DataFrame([[1,2],[3,np.nan],[5,6]], columns=["a","b"], index=["i_1","i_2","i_3"]) df.to_csv("file.csv") yields ,a,b i_1,1,2.0 i_2,3, i_3,5,6.0 What I would like

Why does Assert.AreEqual(1.0, double.NaN, 1.0) pass?

被刻印的时光 ゝ 提交于 2019-12-10 01:10:02
问题 Short question, why does Assert.AreEqual(1.0, double.NaN, 1.0) pass? Whereas Assert.AreEqual(1.0, double.NaN) fails. Is it a bug in MSTest (Microsoft.VisualStudio.QualityTools.UnitTestFramework) or am I missing something here? Best regards, Egil. Update: Should probably add, that the reason behind my question is, that I have a bunch of unit tests that unfortunately passed due to the result of some linear algebraic matrix operation being NaN or (+/-)Infinity. The unit tests are fine, but since

C++ NaN byte representation changes during assignment

时光怂恿深爱的人放手 提交于 2019-12-09 15:34:40
问题 In trying to assign a NaN to a variable on an x64 processor *dest = *(float*)&sourceNaN; where unsigned char sourceNaN[] = {00,00, 0xa0, 0x7f}; The floating point instructions fld and fstp (seen in the disassembly) change the 0xa0 byte to an 0xe0. Thus the destination has an extra bit set. Can someone explain why this is happening? This is a Windows application. The assembly language code: 005C9B9C mov eax,dword ptr [ebp+10h] 005C9B9F fld dword ptr [ebp-80h] 005C9BA2 fstp dword ptr [eax] 回答1:

Force JSON.stringify() to emit NaN / Infinity or JS JSON lib that does so

百般思念 提交于 2019-12-09 13:29:56
问题 I'm looking into the feasibility of adding NaN/Infinity support to a pre-existing scientific application that uses JSONRPC for client/server interactions. Many JSON libs do handle (optionally in some cases) NaNs and Infs, for example: Python json reads and writes Java Jackson reads but writes strings instead of barewords Java GSON reads and writes Javascript can read I'm aware that NaN and Infinity are not supported in the JSON spec, and am aware of the related questions. However, AFAICT the