double

C++ / C# differences with float and double

混江龙づ霸主 提交于 2019-12-29 07:42:21
问题 We are converting a C++ math library to C#. The library mixes the use of floats and doubles (casting between them sometimes) and we are trying to do the same, in order to get the exact same results in C# that we had in C++ but it is proving to be very difficult if not impossible. I think the problem is one or more of the following, but I am not an expert: Converting floats to double and double to floats is causing unpredictable results and done differently in C++ and C# C++ and C# handle

C++ / C# differences with float and double

走远了吗. 提交于 2019-12-29 07:42:12
问题 We are converting a C++ math library to C#. The library mixes the use of floats and doubles (casting between them sometimes) and we are trying to do the same, in order to get the exact same results in C# that we had in C++ but it is proving to be very difficult if not impossible. I think the problem is one or more of the following, but I am not an expert: Converting floats to double and double to floats is causing unpredictable results and done differently in C++ and C# C++ and C# handle

Determining if a string is a double

有些话、适合烂在心里 提交于 2019-12-29 07:33:09
问题 I would like to see if a string contains a double as its sole contents. In other words, if it could possibly be the output of the following function: string doubleToString(double num) { stringstream s; s << num; return s.str(); } 回答1: You want the strtod function. bool isOnlyDouble(const char* str) { char* endptr = 0; strtod(str, &endptr); if(*endptr != '\0' || endptr == str) return false; return true; } 回答2: You can use the Boost lexical_cast to check whether a string contains double or not.

Determining if a string is a double

点点圈 提交于 2019-12-29 07:33:07
问题 I would like to see if a string contains a double as its sole contents. In other words, if it could possibly be the output of the following function: string doubleToString(double num) { stringstream s; s << num; return s.str(); } 回答1: You want the strtod function. bool isOnlyDouble(const char* str) { char* endptr = 0; strtod(str, &endptr); if(*endptr != '\0' || endptr == str) return false; return true; } 回答2: You can use the Boost lexical_cast to check whether a string contains double or not.

How to print out the memory contents of a variable in C?

假如想象 提交于 2019-12-29 03:28:05
问题 Suppose I do a double d = 234.5; I want to see the memory contents of d [the whole 8 bytes] How do I do that? 回答1: double d = 234.5; /* 1. use a union */ union u { double d; unsigned char c[sizeof(double)]; }; union u tmp; size_t i; tmp.d = d; for (i=0; i < sizeof(double); ++i) printf("%02x\n", tmp.c[i]); /* 2. memcpy */ unsigned char data[sizeof d]; size_t i; memcpy(data, &d, sizeof d); for (i=0; i < sizeof d; ++i) printf("%02x\n", data[i]); /* 3. Use a pointer to an unsigned char to examine

How can I accommodate a string with both single and double quotes inside of it in Javascript

寵の児 提交于 2019-12-28 06:21:14
问题 I have an application, and it is fed some HTML. It then needs to put that HTML into a string. This HTML contains single and double quotes. Is it possible, in javascript, to declare a string with information inside of it, that does not use single or double quotes? Thanks, and I guess if it is not possible, does anyone know a simple and easy way to escape these quotes so I can put it in a string? Keep in mind, part of this string will be javascript that I will later need to execute. Thanks! 回答1

How do I in JDBC read a possibly null double value from resultSet?

我的未来我决定 提交于 2019-12-28 05:56:37
问题 I have a column in my database that is typed double and I want to read the value from it using a JDBC ResultSet, but it may be null. What is the best way of doing this? I can think of three options none of which seem very good. Option 1: Bad because exception handling verbose and smelly double d; try { d = rs.getDouble(1); // do something } catch(SQLException ex) { if(rs.wasNull()) { // do something else } else { throw ex; } } Option 2: Bad because two fetches s = rs.getString(1); // or

Why is my Web API method with double args not getting called?

↘锁芯ラ 提交于 2019-12-28 04:25:27
问题 I have a Web API method that takes two double args: Repository interface: public interface IInventoryItemRepository { . . . IEnumerable<InventoryItem> GetDepartmentRange(double deptBegin, double deptEnd); . . . } Repository: public IEnumerable<InventoryItem> GetDepartmentRange(double deptBegin, double deptEnd) { // Break the doubles into their component parts: int deptStartWhole = (int)Math.Truncate(deptBegin); int startFraction = (int)((deptBegin - deptStartWhole) * 100); int deptEndWhole =

Input string was not in a correct format #2

心已入冬 提交于 2019-12-28 04:23:08
问题 double temp; temp = (double)Convert.ToDouble("1234.5678"); Hey Lads and Ladies, I can't for the life of me figure out why the above line isn't working. The above line gives me a runtime error that says; An unhandled exception of type System.FormatException occurred in mscorlib.dll Additional information: Input string was not in a correct format. 回答1: As far as I know the Convert methods use the current locale to do such conversions. In this case I'd guess your current locale would expect a

How to manipulate arrays. Find the average. Beginner Java

帅比萌擦擦* 提交于 2019-12-28 04:05:07
问题 I have a homework assignment and I was wondering if anyone could help me as I am new to Java and programming and am stuck on a question. The question is: The first method finds the average of the elements of an integer array: public double average(int[] data) That is, given an integer array, data, calculate the average of its elements are return the average value. For example, the average of {1, 3, 2, 5, 8} is 3.8. Here is what I have done so far: public double average(int[] data) { int sum =