long-integer

What are not 2 Long variables equal with == operator to compare in Java?

天涯浪子 提交于 2019-11-28 02:35:58
问题 I got a very strange problem when I'm trying to compare 2 Long variables, they always show false and I can be sure they have the same number value by debugging in Eclipse: if (user.getId() == admin.getId()) { return true; // Always enter here } else { return false; } Both of above 2 return values are object-type Long, which confused me. And to verify that I wrote a main method like this: Long id1 = 123L; Long id2 = 123L; System.out.println(id1 == id2); It prints true. So can somebody give me

1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]

主宰稳场 提交于 2019-11-28 01:27:14
This question already has an answer here: Why do these two multiplication operations give different results? 2 answers I'm attempting to calculate 30 days by multiplying milliseconds however the result continually ends up being a negative number for the value of days_30 and I'm not sure why. Any suggestions are greatly appreciated! CODE SNIPPET: // check to ensure proper time has elapsed SharedPreferences pref = getApplicationContext() .getSharedPreferences("DataCountService", 0); long days_30 = 1000 * 60 * 60 * 24 * 30; long oldTime = pref.getLong("smstimestamp", 0); long newTime = System

What's the difference between long long and long

一笑奈何 提交于 2019-11-27 20:32:41
What's the difference between long long and long? And they both don't work with 12 digit numbers (600851475143), am I forgetting something? #include <iostream> using namespace std; int main(){ long long a = 600851475143; } On major 32-bit platforms: int is 32 bits long is 32 bits as well long long is 64 bits On major 64-bit platforms: int is 32 bits long is either 32 or 64 bits long long is 64 bits as well Going by the standard: int must be at least 16 bits long must be at least 32 bits long long must be at least 64 bits Correct me if I'm wrong. If you need a specific integer size for a

Warning: this decimal constant is unsigned only in ISO C90

六月ゝ 毕业季﹏ 提交于 2019-11-27 19:49:46
Piece of code : long rangeVar = 0; rangeVar = atol(p_value); if (rangeVar >= -2147483648 && rangeVar <= 2147483647) On compiling I get: warning: this decimal constant is unsigned only in ISO C90 Thanks in Advance The rules for the types of decimal integer constants changed between the 1990 and 1999 editions of the ISO C standard. In the 1990 version, an unsuffixed decimal integer constant's type is the first of int , long int , or unsigned long int in which its value can be represented. (C90 had no long long or unsigned long long type). In the 1999 and 2011 versions, its type is one of int ,

How to convert a String to long in javascript?

江枫思渺然 提交于 2019-11-27 18:04:37
I have a millisecond timestamp that I need to convert from a String to long. Javascript has a parseInt but not a parseLong . So how can I do this? Thanks Edit: To expand on my question slightly: given that apparently javascript doesn't have a long type, how can I do simple arithmetic with longs that are initially expressed as strings? E.g subtract one from the other to get a time delta? JavaScript has a Number type which is a 64 bit floating point number*. If you're looking to convert a string to a number, use either parseInt or parseFloat . If using parseInt , I'd recommend always passing the

Is “long long” = “long long int” = “long int long” = “int long long”?

你说的曾经没有我的故事 提交于 2019-11-27 17:24:56
I found both long int long and int long long can compile for a variable type. Is there any difference between long int long , int long long , long long and long long int ? In general, is the type identical if it has the same number of long ? 1 long: long l; int long il; long int li; 2 long: long long ll; int long long ill; long int long lil; long long int lli; Also if above is right, are the following declarations also identical? long long* llp; int long long* illp; long int long* lilp; long long int* llip; Vlad from Moscow According to the C++ Standard (7.1.6.2 Simple type specifiers) 3 When

Why is long slower than int in x64 Java?

此生再无相见时 提交于 2019-11-27 17:14:07
I'm running Windows 8.1 x64 with Java 7 update 45 x64 (no 32 bit Java installed) on a Surface Pro 2 tablet. The code below takes 1688ms when the type of i is a long and 109ms when i is an int. Why is long (a 64 bit type) an order of magnitude slower than int on a 64 bit platform with a 64 bit JVM? My only speculation is that the CPU takes longer to add a 64 bit integer than a 32 bit one, but that seems unlikely. I suspect Haswell doesn't use ripple-carry adders. I'm running this in Eclipse Kepler SR1, btw. public class Main { private static long i = Integer.MAX_VALUE; public static void main

Long.getLong() failing, returning null to valid string

狂风中的少年 提交于 2019-11-27 17:08:28
问题 I've spent the past two hours debugging what seems extremely unlikely. I've stripped the method of a secondary Android Activity to exactly this: public void onClick(View v) { String str = "25"; long my_long = Long.getLong(str); } // onClick (v) And yeah, I get a crash with the good ol' NullPointerException: 09-11 02:02:50.444: ERROR/AndroidRuntime(1588): Uncaught handler: thread main exiting due to uncaught exception 09-11 02:02:50.464: ERROR/AndroidRuntime(1588): java.lang

How to convert / cast long to String?

依然范特西╮ 提交于 2019-11-27 16:45:19
I just created sample BB app, which can allow to choose the date. DateField curDateFld = new DateField("Choose Date: ", System.currentTimeMillis(), DateField.DATE | DateField.FIELD_LEFT); After choosing the date, I need to convert that long value to String, so that I can easily store the date value somewhere in database. I am new to Java and Blackberry development. long date = curDateFld.getDate(); How should I convert this long value to String? Also I want to convert back to long from String. I think for that I can use long l = Long.parseLong("myStr"); ? Gregory Pakosz See the reference

Possible lossy conversion from long to int, JAVA

主宰稳场 提交于 2019-11-27 16:16:10
I am trying to pass long value to the method and use it there to create a Long Array. However, I am getting "possible lossy conversion from long to int" error while creating an array long[] array = new long[n]; although I have not used any integers values. import java.util.Scanner; import java.util.ArrayList; public class test{ public static void main(String[] args){ Scanner input = new Scanner(System.in); long n = input.nextLong(); System.out. although("result is " + n + " is " + testing(n)); } private static long testing(long n){ long[] array = new long[n]; return 0; } } Array dimensions can