double

printing double in binary

In 'Thinking in C++' by Bruce Eckel, there is a program given to print a double value in binary. (Chapter 3, page no. 189) int main(int argc, char* argv[]) { if(argc != 2) { cout << "Must provide a number" << endl; exit(1); } double d = atof(argv[1]); unsigned char* cp = reinterpret_cast<unsigned char*>(&...

Loss of precision - int -> float or double

I have an exam question i am revising for and the question is for 4 marks "In java we can assign a int to a double or a float". Will this ever loose infromation and why? I have put that because ints are normally of fixed length or size - the precision for sotring data is finite, where storing information in floating point can be infin...

C++ calculation evaluated to 0

I'm parsing a file and trying to decode coordinates to the right unit. What happens is that this code is evaluated to 0. If I type it into gdb the result is correct. int pLat = (int)( (argv[6].data() == "plus" ? 1 : -1) * ( atoi(argv[7].data()) + atoi(argv[8].data()) / 60. + atoi(argv[9]...

Compare sign of two doubles

What's the fastest way to compare sign on a double? I know that a double has a "sign bit" but I'm not sure if the way I'm "looking for it" in its binary rep is a good idea or not. Barring "portability" issues, can someone tell me what's going on with this code in MSVC++? #include <stdio.h> int main() { double z = 5.0 ; __int64 b...

split double in c wihout any libary

Hello I have a question for a c programmer out there, we have a tast at school to create a soft real time system in an operation system made by our teacher. Well that is all fine and dandy, we have chosen to create a system that calcuate how many unites of medicine a diabetic need based on his or hers blood sugar. It does not need to be ...

C int, float, double

There are certain int values that a float can not represent. However, can a double represent all values a float can represent? (My intuition says yes, since double has more fractional bits & more exponent bits, but there might be some silly gotchas that I'm missing). Thanks! ...

Double precision values

Just a day before I participated in the qualification round of Google Code Jam. This is my first experience of such an online coding contest. It was really fun. There were three problems given of which i was able to solve two. But on one of the problems I was asked to work with values that are really huge. I am a Java guy and I thought ...

JAXB, BigDecimal or double?

I working on different web-services, and I always use WSDL First. JAXB generates for a Type like: <xsd:simpleType name="CurrencyFormatTyp"> <xsd:restriction base="xsd:decimal"> <xsd:totalDigits value="13"/> <xsd:fractionDigits value="2"/> <xsd:minInclusive value="0.01"/> </xsd:restriction> </xsd:simpleTy...

C Different answers for a variable when running 'Debug' and 'Start without debug'

I keep getting this weird output from my code everytime I use the 'start without degugging' (ctrl-F5) as opposed to normal 'debug' (F5). When I try to find the following value of norm_differnece in debug (pressing F5) mode, it gives me the correct answer for norm_difference normdifference = 1.000000 but in 'start without debugging' (...

casting doubles to integers in order to gain speed

Hello all, in Redis (http://code.google.com/p/redis) there are scores associated to elements, in order to take this elements sorted. This scores are doubles, even if many users actually sort by integers (for instance unix times). When the database is saved we need to write this doubles ok disk. This is what is used currently: snprin...

How do I convert a double into a string in C++(without scientific notation)?

How to convert a double into a floating-point string representation without scientific notation in C++. "Small" samples (effective numbers may be of any size, such as 1.5E200 or 1e-200) : 0.0000000000000000000000000000000000000000000000000000000023897356978234562 Thank you. ...

Double.TryParse() input decimal separator different than system decimal separator

I have a source XML that uses a dot (".") as a decimal separator and I am parsing this on a system that uses a comma (",") as a decimal separator. As a result, value of 0.7 gets parsed with Double.TryParse or Double.Parse as 7000000. What are my options to parse correctly? One of them is to replace dots in source with commas with Stri...

auto vectorization on double and ffast-math

Why is mandatory to use -ffast-math with g++ to achieve vectorization of loop using doubles? I don't like ffast-math because I don't want to loose precision. ...

Is there a better way to check if a value is bigger than of type double?

double x; cin>>x; if( x > 1.7976931348623157e+308 || x < -1.7976931348623157e+308 ) { cout<<"value not in range"<<endl; exit(1); } Is there like a DOUBLE_MAX or DOUBLE_MIN and would I need to include any header files? ...

Can we overload the Point object in C# so it supports doubles?

I am drawing some graphs using the Point object and I want to set it so it supports doubles as its parameters. I am working on Visual C#, WindowsConsoleApplication Thank you. ...

Possible loss of precision / [type] cannot be dereferenced

I have been looking around a lot but i simply can't find a nice solution to this... Point mouse = MouseInfo.getPointerInfo().getLocation(); int dx = (BULLET_SPEED*Math.abs(x - mouse.getX()))/ (Math.abs(y - mouse.getY()) + Math.abs(x - mouse.getX()))* (x - mouse.getX())/Math.abs(x - mouse.getX());...

How to convert an object into a double?

I am working on VS C# on the following code, which converts an user input math expression and computes it. MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl(); sc.Language = "VBScript"; sc.ExecuteStatement( "function pi\n" + "pi = 3.14159265\n" + "end functi...

PHP/MySQL won't update decimal field

I have this query: UPDATE table_name SET field_1 = field_1 +100, field_2 = field_2 +100, field_3 = field_3 +100 WHERE id = 1 LIMIT 1; Where Field_1 is regular integer, Field_2 is decimal(15,6) and Field_3 is double(15,6). When I run this query from php script they update just field_1 and nothing happen with field_2 an...

Save matrix of double values in OpenCV

I have an OpenCV matrix of double (CV_32F) values. I'd like to save it to the disk. I know, I could convert it to an 1-Channel 8-bit IplImage and save it. But that way, I loose precision. Is there a way to save it directly in the 32-bit format, without having to convert it first? It also would be nice, if the resulting file would have an...

how to control textbox type to double in visual basic?

Hi, I'd like to make a textbox that accepts only numbers, but not integer, but rather double. I've read here about e.Handled = Not Char.IsDigit(e.KeyChar) and it works, but again, it can be used only for integer, since it declines decimal point. Another thing I've read here is If Not Double.TryParse(TextBox2.Text, value) Then .... and i...