double

Convert a Cell of Strings to a Double in Matlab

♀尐吖头ヾ 提交于 2019-12-20 03:17:06
问题 How do i convert a Cell as the following: >> A = [{'2'};{'2'};{'****'};{'23'};{'23.6'}] A = '2' '2' '****' '23' '23.6' To a double as the Following A = 2.0000 2.0000 NaN 23.0000 23.6000 回答1: str2double can be called directly on a cell array of strings: >> X = str2double(A) X = 2.0000 2.0000 NaN 23.0000 23.6000 On an unrelated note, the notation used to define the cell array A can be simplified a bit: >> A = {'2'; '2'; '****'; '23'; '23.6'} A = '2' '2' '****' '23' '23.6' no need for all those

Compute the double value nearest preferred decimal result

别等时光非礼了梦想. 提交于 2019-12-20 03:05:28
问题 Let N(x) be the value of the decimal numeral with the fewest significant digits such that x is the double value nearest the value of the numeral. Given double values a and b, how can we compute the double value nearest N(b)-N(a)? E.g.: If a and b are the double values nearest .2 and .3, the desired result is the double value nearest .1, 0.1000000000000000055511151231257827021181583404541015625, rather than than the result of directly subtracting a and b, 0

How is float variable auto-promoted to double type?

蓝咒 提交于 2019-12-20 02:54:34
问题 I know in C and Java, float's underlying representation is IEEE754-32, double is IEEE754-64. In expressions, float will be auto-promoted to double . So how? Take 3.7f for example. Is the process like this? 3.7f will be represented in memory using IEEE754. It fits in 4 bytes. During calculation, it may be loaded into a 64-bit register (or whatever 64-bit place), turning the 3.7f into IEEE754-64 represent. 回答1: It is very implementation-dependent. For one example, on x86 platform the set of FPU

Floating point computation changes if stored in intermediate “double” variable

落花浮王杯 提交于 2019-12-20 02:27:15
问题 I am trying to write a simple log base 2 method. I understand that representing something like std::log(8.0) and std::log(2.0) on a computer is difficult. I also understand std::log(8.0) / std::log(2.0) may result in a value very slightly lower than 3.0. What I do not understand is why putting the result of a the calculation below into a double and making it an lvalue then casting it to an unsigned int would change the result compared to casting the the formula directly. The following code

PInvoke: Issue with returned array of doubles?

霸气de小男生 提交于 2019-12-20 02:27:12
问题 I am using PInvoke to call a C++ function from my C# program. The code looks like this: IntPtr data = Poll(this.vhtHand); double[] arr = new double[NR_FINGERS /* = 5 */ * NR_JOINTS /* = 3*/]; Marshal.Copy(data, arr, 0, arr.Length); With Poll() 's signature looking like this: [DllImport("VirtualHandBridge.dll")] static public extern IntPtr Poll(IntPtr hand); The C-function Poll 's signature: extern "C" __declspec(dllexport) double* Poll(CyberHand::Hand* hand) Unless I'm having a huge brain

GWT - DoubleBox with more than 3 decimal places

帅比萌擦擦* 提交于 2019-12-20 01:36:44
问题 I'm creating an user interface using GWT and there're many boxes of double values but when I set some variable which contains more than 3 decimal places my DoubleBox doesn't accept and truncates the number letting just 3 places. Is it normal? What's the best solution? Thank you. 回答1: As the javadoc says DoubleBox is a ValueBox using a DoubleParser and DoubleRenderer . Those rely on NumberFormat.getDecimalFormat() which will trunk at 3 decimals in most (if not all) locales (for the default

Grep error due to expanding variables with spaces

妖精的绣舞 提交于 2019-12-20 01:36:08
问题 I have a file called " physics 1b.sh ". In bash, if I try x="physics 1b" grep "string" "$x".sh grep complains: grep: physics 1b: No such file or directory. However, when I do grep "string" physics\ 1b.sh It works fine. So I guess the problem is something to do with the variable not being expanded to include the backslash that grep needs to recognize the space. How do I get this to work? Using bash 3.2, mac os 10.6. Edit: Never mind, the problem was that x was set to " physics 1b" , but when I

Convert C# double to Delphi Real48

大兔子大兔子 提交于 2019-12-20 00:53:41
问题 I've found the following question Convert Delphi Real48 to C# double but I want to go the other way, C# to Delphi. Does anyone know how this can be done? I've tried reverse engineering the code but without much luck. Update: I'm after C# code that will take a double and convert it into a Real48 (byte[] of size 6). Thanks 回答1: I came across this thread looking for the same code. Here is what I ended up writing: public static byte [] Double2Real48(double d) { byte [] r48 = new byte[6]; byte []

Clear trailing 0's on a double?

a 夏天 提交于 2019-12-19 22:01:40
问题 I have a double thats got a value of something like 0.50000 but I just want 0.5 - Is there any way to get rid of those trailing 0's? :) 回答1: standard c format statements. NSLog(@" %.2f", .5000) 回答2: In C, printf("%g", 0.5000); Note: (from GNU libc manual) The %g and %G conversions print the argument in the style of %e or %E (respectively) if the exponent would be less than -4 or greater than or equal to the precision ; otherwise they use the ‘%f’ style. A precision of 0, is taken as 1.

C# High double precision

流过昼夜 提交于 2019-12-19 19:40:01
问题 I'm writing a function that calculates the value of PI, and returns it as a double. So far so good. But once the function gets to 14 digits after the decimal place, it can't hold any more. I'm assuming this is because of the double's limited precision. What should I do to continue getting more numbers after the decimal place? 回答1: I wouldn't do it in floating point at all. Recall that your algorithm is: (1 + 1 / (2 * 1 + 1)) * (1 + 2 / (2 * 2 + 1)) * (1 + 3 / (2 * 3 + 1)) * (1 + 4 / (2 * 4 +