long-integer

How does java.sql.Date work with negative dates?

主宰稳场 提交于 2019-12-07 00:02:39
问题 I had a situation where the Java runtime returned sort of "inverted" millisecond values when reading dates from the database (in java.sql.Date ). The millisecond value was approximately the same amount of days, but counted backwards from year 0. The problem was solved by just restarting the Java runtime. But: I found out that Java handles these "inverted" values almost correctly except of the week day. When you run the following code: System.out.println(new java.util.Date(253402214400000l));

IEEE-754 Double (64-bit floating point) vs. Long (64-bit Integer) Revisited

断了今生、忘了曾经 提交于 2019-12-06 18:51:40
问题 I'm revisiting a question (How to test if numeric conversion will change value?) that as far as I was concerned was fully solved. The problem was to detect when a particular numeric value would overflow JavaScript's IEEE-754 Number type. The previous question was using C# and the marked answer worked perfectly. Now I'm doing the exact same task but this time in Java and it doesn't work. AFAIK, Java uses IEEE-754 for its double data type. So I should be able to cast it back and forth to force

Python: Is there a way to keep an automatic conversion from int to long int from happening?

不打扰是莪最后的温柔 提交于 2019-12-06 18:35:08
问题 Python is more strongly typed than other scripting languages. For example, in Perl: perl -E '$c=5; $d="6"; say $c+$d' #prints 11 But in Python: >>> c="6" >>> d=5 >>> print c+d Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot concatenate 'str' and 'int' objects Perl will inspect a string and convert to a number, and the + - / * ** operators work as you expect with a number. PHP is similar. Python uses + to concatenate strings so the the attempted

C++ - ridiculous long long range

ⅰ亾dé卋堺 提交于 2019-12-06 11:08:01
Me and my friend have just encountered a very weird issue with long long range. So basically, my computer has a 64bit processor but a 32 bit system on it. He has both 32 bit OS and CPU. First, we printfed sizeof(long long) . For both of us that was 8. Then we did this: long long blah = 1; printf ("%lld\n", blah<<40); For me this returns 1099511627776 (which is the correct result). For him it is 0. How is that possible? We both have the same sizeofs. Thanks in advance. EDIT: I compiled and ran it under Win7 with Code Blocks 12.11. He uses Win XP and the same version of CB. EDIT2: Source codes

C++ literal integer type

风流意气都作罢 提交于 2019-12-06 09:46:09
Do literal expressions have types too ? long long int a = 2147483647+1 ; long long int b = 2147483648+1 ; std::cout << a << ',' << b ; // -2147483648,2147483649 Yes, literal numbers have types. The type of an unsuffixed decimal integer literal is the first of int , long , long long in which the integer can be represented. The type of binary, hex and octal literals is selected similarly but with unsigned types in the list as well. You can force the use of unsigned types by using a U suffix. If you use a single L in the suffix then the type will be at least long but it might be long long if it

Python 'long' object has no attribute 'to_bytes'?

五迷三道 提交于 2019-12-06 05:38:36
I'm trying to use a bitcoin address validator written in Python from here : This snippet gives me trouble though: def decode_base58(bc, length): n = 0 for char in bc: n = n * 58 + digits58.index(char) return n.to_bytes(length, 'big') I understand that n is either an int or a long, but neither has a method called to_bytes, so I don't really understand how this code could have ever worked? Does anybody know what's wrong here? Am I doing something wrong, or is this code simply written wrong? All tips are welcome! Python 2.7 int and long don't have the .to_bytes method. Python 3.2 int has the .to

c - Long Long to char conversion function in embedded system

…衆ロ難τιáo~ 提交于 2019-12-06 05:09:32
Im working with a embedded system and I need implement a way to convert long long to char. The problem is that I can not use sprintf in this system to do that, so im looking for alternative ways/functions to implement this. Suggestions of implementations for LongLongToChar function are welcome. Google "itoa". There are many variations. Here's an example. char* itoa(int val, int base){ static char buf[32] = {0}; int i = 30; for(; val && i ; --i, val /= base) buf[i] = "0123456789abcdef"[val % base]; return &buf[i+1]; } Specifically, here's an 'lltoa'. #include <stdio.h> #include <limits.h> char*

Convert C++ string variable to long

心不动则不痛 提交于 2019-12-06 01:26:52
问题 I have a variable: string item; It gets initialized at run-time. I need to convert it to long. How to do it? I have tried atol() and strtol() but I always get following error for strtol() and atol() respectively: cannot convert 'std::string' to 'const char*' for argument '1' to 'long int strtol(const char*, char**, int)' cannot convert 'std::string' to 'const char*' for argument '1' to 'long int atol(const char*)' 回答1: Try like this: long i = atol(item.c_str()); 回答2: c++11: long l = std::stol

Overflow exception is throwing- even the value exceeds the limit

十年热恋 提交于 2019-12-06 01:01:13
Why the following code Gives output as -2 instead for throwing overflow exception ? long x = long.MaxValue; long y = long.MaxValue + x; The actual behaviour depends on project settings, unchecked etc. To ensure overflow exception use checked , e.g. checked { long x = long.MaxValue; long y = long.MaxValue + x; } Presumably because you're executing it in an unchecked context. Arithmetic on the primitive integer types can execute in a checked or unchecked context . Operations which overflow throw an exception in a checked context, and just use the bottom N bits (depending on the type) in an

Long polling in Laravel (sleep() function make application freeze)

十年热恋 提交于 2019-12-05 23:47:53
问题 I'm trying to program long polling functionality in Laravel, but when I use the sleep() function, the whole application freezes/blocks until the sleep() function is done. Does anyone know how to solve this problem? My javascript looks like this: function startRefresh() { longpending = $.ajax({ type: 'POST', url: '/getNewWords', data: { wordid: ""+$('.lastWordId').attr('class').split(' ')[1]+"" }, async: true, cache: false }).done(function(data) { $("#words").prepend(data); startRefresh(); });