Double

Double is a primitive data type used to store fractional numbers that holds a double-precision floating-point (often 64 bits).

Int

A data type that represents an integer

Difference clock cycles

Quality Example
Faster

"The difference is that int are still faster than double because it takes very few clock cycles to do arithmetic operations on int"

from question "Algorithm speed with double and int?"

Slower code

"Using and at the same time to check equality on a int results in slower code because it takes two comparisons instead of one taking the double amount of time"

from question "When comparing for equality is it okay to use `==`?"

Performance better version

Quality Example
Faster

"The versions using diff are especially impacted ave_diff with int constants is about 2.5 times faster than the double contants version"

from question "How to return the last value in a vector that met a certain condition"

Better

"Note how i cast the result to int which is better suited for years than the double precision returned by extract"

from question "Condition on a timestamp column to select data for a year"

"Byte takes less memory than double and int and provides better performance than bigger datatypes especially better than double"

from question "Byte z[] = new byte[5]; - What does this mean?"

Precision bits actual

Quality Example
Precision less bits

"However if you have large enough number the limit checking does not work because 64bit double precision has less bits usually 54 but this is not defined in standard for the fractions part than a 64bit int"

from question "Converting strings to integers the right way"

Range more

"Double has range more than a 64-bit int but its precision is less dues to its representation since double is 64-bit as well it can t fit more actual values"

from question "Find max integer size that a floating point type can handle without loss of precision"

Greater

"If a 64-bit long is written as an int and is greater than 2 53 ieee double has a 52-bit mantissa then reading it as a double will lose precision"

from question "How to read a number using minimal-json"

Better match overload

Quality Example
Better

"With gcc 4.9 it prints error because the second overload isn t discarded and int is a better match than double"

from question "G++4.9 and g++5 different behaviour when narrowing in initializing list"

"Is simply a hard error because f int is a better match than f double even though the f int overload causes a hard error further on"

from question "Why do static member functions need to have an implicit object parameter according to §13.3.1/4?"

"Imho int looks better than double in your task"

from question "C# adding dynamic variables in loop"

Better results

"If you use int between -128 and 127 you will get much better results than double from -128 to 127 because the former uses caches values the later does not"

from question "Performance of the Number class"

Faster slower machine

Quality Example
Faster pow

"This can t help performance either since pow double int is significantly faster than pow double double in general"

from question "How to raise double to array powers in Eigen"

Slower

"With it is nub on and comparing big int is slower than comparing double"

from question "Exponent operator performance"

"Incrementing the value might be a special case but it s possible that on your machine incrementing double is slower than incrementing int"

from question "One Thread slower than another even they do the same thing"

"Even dividing int is slower than multiplying floats or double in some cases"

from question "Java date calucation truncates decimal place at result"

Less

"Similarly when i cast a double that is less than the minimum possible int i also get -2147483648"

from question "Handling overflow when casting doubles to integers in C"

Little less

"You will get 24 if pow 10 2 returns a double that is little less than 100 99.9999999998765 which when cast to int would be truncated resulting in 99 and thus you get"

from question "Undesired output with modulo operator and ' pow '"

Much slower

"Double is much slower than int"

from question "Subsetting in data.table"

Faster

"Maybe division between double and int is faster than it between double"

from question "Efficiency of summing images using MATLAB and OpenCV"

"Int subtractions are 2.5 times faster than double subtractions on my machine"

from question "Int vs float arithmetic efficiency in Java"

"Int multiplications however are only 1.5 times faster than double multiplications"

from question "Int vs float arithmetic efficiency in Java"

"So i asked myself can a double be faster than a int"

from question "Numerical optimization"

64-bit instructions equivalent

Quality Example
Types more instructions

"On a 32-bit machine doing addition and comparison on 64-bit int types takes more instructions than doing the equivalent on double s"

from question "Cause of comparing long slower than comparing double"

Less

"That wouldn t work on platforms where a double is less than 64 bits but it would work on many platforms without 64-bit int"

from question "How do I use two 32-bit integers as a 64-bit in C?"

Arithmetic complex modern

Quality Example
More efficient

"If you want the modulus use as it gives an int and would be more efficient than double arithmetic"

from question "Difference in Java, if any, between the % operator and the IEEEremainder() method?"

Precision much more complex

"As for the last question floating point arithmetic particularly double precision is much more complex than int arithmetic so on a reasonably modern pipelined processor each instruction will take longer to execute"

from question "G++, doubles, optimization and a big WTF"

Type lower rank

Quality Example
Lower

"Num is a of type const int which is of lower rank when compared to the type of z which is double"

from question "Warning when converting to `int' from `double'"

"So no arguments after the 1st one get automatically converted except as defined by default argument conversions basically any int type with a rank lower than int to int and any floating-point type with a rank lower than double to double thank you pascal cuoq"

from question "Printing an integer as a Floaing point number"

Higher values

"To prevent the code from overflowing the int value space you should could change the type of res to double long anything that can hold higher values than int"

from question "How to find the largest power of 2 less than the given number"

Lower ranges

"If we use float data type in java we have to add f at the end of floating point literal as java assumes it to be double data type and gives an error why not do the same for short and byte as both have lower ranges than int"

from question "Why do we use `f` for float datatypes but not for byte and short?"

Precision general precise

Quality Example
More

"But this isn t true because double is more general than int and therefore int is the most-specific option in this case"

from question "Boxing to Object type to avoid compilation failure"

Better

"Double is better than int though as it will help you keep precision"

from question "Which Data Structure to use for getting the desired result"

Less

"Further the precision of double may be less than int introducing other problems"

from question "Evaluating an integer using pow() function from math"

More precision

"Double doesn t have infinite precision and you can t gain more precision than a double has by converting a double to a bigdecimal like you can t gain more precision with an int when you do which is 0.0 because it widens an int to a double"

from question "Java DecimalFormat losing precision while formatting double"

"Double can hold more precision than int"

from question "Unable to store Bigint data to mysql database using send_long_data"

More precsion

"This is important because if the int needs more precsion than 52-bits the precision is too low for a double"

from question "What happens when I change int 8 to int 16"

Less precise

"Since int is less precise than double i thought i needed to cast it when parsing it into a method"

from question "Parse different data type Java"

More general type

"Double can in a way be seen as a more general type than int"

from question "Java - what's the difference between 2 little codes"

Parameter sizeof greater

Quality Example
Smaller

"It doesn t matter if second member would be int short or whatever - as long as it is smaller than double sizeof struct will be 16"

from question "Structure size issue, claiming unrquired memory?"

Larger

"The undefined behaviour as identified in other answers is explained on my intel platform with vc as that the f format specifier expects a double on the stack which is larger than an int so when it retrieves the value it retrieves more bytes than of an int and now assumes the next parameter at a diferent position on the stack causing z to be printed wrong it is not z that is printed"

from question "Unusual behaviour in case of nested scope variables"

Length value

Quality Example
Less

"Or a value for int a that is 6 less than double c"

from question "Calling a method from the main to output a phrase in java"

More

"Double s length is way more than int that s why you should be checking int first"

from question "Overloaded Methods with User Input (ReadLine())"

Aware inexactness inexact

Quality Example
Less

"As far as i m aware so long as the spacing between two double is less than 2 then int values stored as double should be exact - and though 10 14 is pushing it this should be an exact int since 10 14 2 46.507 2 53"

from question "Exp10 different to pow(10)"

Space memory outofmemory

Quality Example
Less space

"I don t understand how an int 63823 takes up less space than a double 1.0"

from question "Why is a double always 8 bytes and an int always 4 bytes, even if the int has more digits?"

Solution small fractions

Quality Example
Quicker float

"A solution using int only calculations should be quicker than float double calculations is"

from question "C# convert YUV 4:2:2 to RGB?"

Likely overruns bear

Quality Example
Larger

"Bear in mind that if the double returned is larger or smaller than that which can be held in an int then the program behaviour is undefined"

from question "What happens when storing a function's return type in a variable of a different type?"

Narrower type positive

Quality Example
Type substantially narrower

"The int portions of the logarithms of 31 and 310 use different numbers of bits so there are different numbers of bits left for the significand so they end up being rounded to slightly different values. as long as the int type is substantially narrower than the double type the calculated limit will be much larger than the error in log10"

from question "Sort array of integers lexicographically C++"

Narrower

"I believe the following works as a sort comparison function for positive int provided the int type used is substantially narrower than the double type 32-bit int and 64-bit double and the log10 routine used returns exactly correct results for exact powers of 10 which a good implementation does"

from question "Sort array of integers lexicographically C++"

Specific void first

Quality Example
More

"By contrast void doitagain int is more specific than void doitagain double because int is a subtype of double according the the jls"

from question "Bug with varargs and overloading?"

Indeed more

"An implicit conversion from byte to int is indeed more specific than an implicit conversion from byte to double according to widening primitive conversions rules"

from question "When passing arguments to methods become ambiguous in Java?"

Less specific

"So overloadedsingleparam double a is less specific than void overloadedsingleparam int a when an int value is passed as argument"

from question "Method overloading : Single parameter vs alternating parameters"

More specific

"We could check that void mymethod int i is more specific than void mymethod double a if any invocation handled by the first method can be passed on to the other one without a compile-time type error"

from question "When passing arguments to methods become ambiguous in Java?"

Larger range bigger

Quality Example
Way greater

"The range of double is way greater than the range of 32 or 64 bit int which is why std floor returns a double"

from question "Does casting to an int after std::floor guarantee the right result?"

Larger 64-bit

"Typically a double is 64-bit ieee floating point with roughly 52 bits precision and with range much larger than 64-bit int so magnitude is no problem"

from question "How to convert int64-fixed-point to double?"

Smaller values

"Another option would be to add a cast not recommended due to the same loss of information the error warns you about - the fractional part will simply be removed from the value and double can hold way larger and smaller values than int"

from question "Incompatible types: possible lossy conversion from double to int with switch case"

Larger

"For platforms where int is larger than double it s obviously false"

from question "Are all integer values perfectly represented as doubles?"

"Because a double which f expects probably is larger than an int on your platform"

from question "Printing int variable in float format"

"A double is 1 typically larger than an int and 2 has some internal structure"

from question "Type Casting in C++"

"Your upccode int is larger than the long data type so i tried it with double which is a float but works"

from question "Javascript converted to Excel VB Function Produces #NUM! error"

"Many processors and or compilers implement long double types larger than any int type regardless of name and there are processors with 32 byte pointers"

from question "For each scalar `T`, is there any guarantee an integer of the same size exists?"

"If you are not storing infinity nowhere and use it just for comparison you can use double infinity which is larger than int and long max value"

from question "Interpret infinity in a knapsack task"

"You do explicit type casting to get your result in int because double is a larger data-type than int"

from question "Convert Double to specific form"

"Because a double is larger than an int this accesses the 4 bytes of the original int and an extra 4 bytes on the stack"

from question "Void pointer = int pointer = float pointer"

"When the result of math.pow i j a double is larger than integer.max_value and you cast to an int then the result is integer.max_value"

from question "Why is my program not giving the expected output?"

"Double is larger than an int hence the overflow"

from question "Overflow Exception Error"

Better

"It would really depend on the processor and the range of the int which is better and using double would resolve most of the range issues"

from question "Rounding integers routine"

Array less

"If a value in the double array is less than the int value at the same position of the two dimensional array then in that part of the boolean array the value would is true"

from question "Create two dimensional boolean array from two other arrays"

More

"Operations on float and especially double cost more than on int"

from question "Super fast median of matrix in opencv (as fast as matlab)"

Smaller range

"Int or int32 has a much smaller range than double"

from question "When cast NaN to int, why does the value change depending on whether it is assigned to a variable or not?"

Much smaller

"Don t forget that the range of int is much smaller than the range of double"

from question "Convert double to int"

Range much smaller

"1 int range is much smaller than double and for pow 2 100 that fails"

from question "Pow function not working properly in Code::Blocks IDE"

Not bigger

"This will work as long as the double is not bigger than what can fit in an int"

from question "Trouble generating random numbers?"

Far greater

"Another reason is that the range of double is far greater than that of int"

from question "Does casting to an int after std::floor guarantee the right result?"

Larger numbers

"Because double can contain larger numbers than int or long"

from question "Why Math.Ceiling returns double?"

Higher

"If your resulting double has higher int value then simple int math sometimes stops working"

from question "Log of unsigned long long int argument"

Value bigger

"I wanted to check if a double value is bigger than maximum int value but because converting function does not return an optional value i am not be able to check by using optional binding"

from question "Why converting Double to Int doesn't return optional Int in Swift?"

Bigger numbers

"Clearly calling int x on a double is asking for trouble since double can store bigger numbers than int"

from question "Compare two doubles with different number of decimal places in C#"

Bigger maximum

"I know that there s another way to check if a double number is bigger than maximum int value but i m curious as why it s happening this way"

from question "Why converting Double to Int doesn't return optional Int in Swift?"

Smaller sizeof

"Since sizeof int is very probably smaller than sizeof double this is going to lead to horror"

from question "Access violation writing location 0x011CF000"

Much wider

"The range of double is much wider than the range of int or long"

from question "Why does Math.Floor(Double) return a value of type Double?"

Range wider

"Can be false when int range is wider than double uncommon and dx is a rounded value whose next higher representable value to 2 greater"

from question "Casting between int, float and double in C"

Greater

"What i need to do it iterate over a list find the first int which is greater than 3 and is even then just double it and return it"

from question "Difference between traditional imperative style of programming and functional style of programming"

Greater precision

"And the second calculation 33 5.0 the result is actually promoted to double which has greater precision than int and resulted to decimal"

from question "Why does this basic java code yield different outputs?"

Value also larger

"The largest double value is also larger than the largest int so it would have to be a long"

from question "Why does Math.floor return a double?"

Bigger

"You can convert your object into double and then into int but you should take care as double value is much bigger than int"

from question "Excel.Office.Interop is returning double even when it is an integer"

"A double is bigger than an int"

from question "Creat random number in double format, eclipse stop working"

"The double has a bigger mantissa the int bits of the real number"

from question "What is the difference between float and double?"

"Double is much bigger than int"

from question "How to parse Int with a value more than 2147483647 from JSON in Swift"

"One of long long and double is bigger than 3 int and a multiple of 8"

from question "Specifying 64-bit alignment"

"A double is also probably bigger than an int"

from question "Can methodSignatureForSelector: create a "catch-all" method signature?"

"If you tell it the top of the stack has a double and double is bigger than int you ve now just told it to take extra bytes off of the stack which is terrible"

from question "Strange output for function with variable number parameters of type double"

Type larger

"You need to use 2 even if the number of bits in your int type is larger than the precision of a double since the number of used bits in the most significant value might only be 1"

from question "Conversion Big Integer <-> double in C++"

Wider range

"Also given that double has a wider range what would one return for those out of range int values"

from question "Why Math.Ceiling returns double?"

Smaller

"You could try to add some value to the double to make sure it s bigger or smaller than an int can be"

from question "How to not convert double to int C#?"

"And since float is typically promoted to double with varargs calls if your int is smaller than your double this will break"

from question "Printf function in c"

"That means a float will be a double and anything smaller than an int will be an int"

from question "Why does printf("%f",0); give undefined behavior?"

"In the third case double precision loss is much smaller than the int and you get something like"

from question "Why can't I divide integers correctly within reduce in Swift?"

"In vararg functions such as printf int smaller than int are promoted to int and floats smaller than double are promoted to double"

from question "C++ union to represent data memory vs C scalar variable type"

"4 + 4 since int is smaller size compared to double padding of double size is done"

from question "Structure Padding"

Back to Home
Data comes from Stack Exchange with CC-BY-SA-3.0