c++,long-integer,modulus,integer-overflow

Many compilers offer a 128-bit integral type. For example, with g++ you can make a function static inline int64_t mulmod(int64_t x, int64_t y, int64_t m) { return ( (__int128_t)x * y) % m; } Aside: if you can, try to stick to unsigned integer types when you're doing modular arithmetic....

java,php,wsdl,long-integer,soap-client

Try passing in a SOAP_ENC_OBJECT $struct = new stdClass(); $struct->item1 = $item1; $response = $client->RetrieveUserGPSDataVisualization(new SoapVar($struct, SOAP_ENC_OBJECT)); ...

intellij-idea,javac,long-integer

You must have Long literals in Java ending with an L, adding an L to your integer will correct your issue, like so: Long s = 9223372036854775806L This is because by default Java interprets all integers as 32-bit (int), the suffix L ensures that your integer is interpreted as 64-bit....

The problem is that your long value is overflowing. Because Long.MIN_VALUE is negative for a signed long, Long.MAX_VALUE-Long.MIN_VALUE is larger than Long.MAX_VALUE and therefore doesn't fit in the long during the intermediate computations. Try using nextLong instead: public static long randomLong() { Random ran = new Random(); return ran.nextLong(); }...

python,casting,floating-point,int,long-integer

It appears that what is happening is that the list comprehension is polluting your namespace. eg. k = 0 [k for k in range(10)] After executing the above code in python 2.x the value of k will be 9 (the last value that was produced by range(10)). I'll simplify your...

java,binary,long-integer,biginteger

You are counting the bits wrong: public void test() { long value = 0x4000863; //This value is actually read from a file long bigger = 0x8000000000000000L; BigInteger test = new BigInteger(Long.toString(value)); System.out.println("L:" + Long.toBinaryString(value) + "\r\nB:" + test.toString(2) + "\r\nB63:" + test.testBit(63)); test = new BigInteger(Long.toString(bigger)); System.out.println("L:" + Long.toBinaryString(bigger) +...

java,loops,netbeans,long-integer

It is as easy as it looks like :) long l = 10000000000L; while (l < 10000000000000L) { } for (long k = 0; k < 10000000000000L; k++) { } ...

objective-c,c,casting,double,long-integer

Casting a variable will result in the runtime code doing the conversion and the resulting overflow is producing the max negative number (0x80000000 an undefined result, but what this runtime is doing). Casting the constant will cause the compiler to convert the number and it does convert to the maximum...

c++,casting,double,long-integer,unsigned

The problem arises with your variable distFromPlanets which resolves to -2.7e+9, as distEarthToSun = 9.3e+7 and newSunDist = 2.8e+9. Therefore 9.3e+7 - 2.8e+9 does approximately equal -2.8e+9. I'm no astronomer, but if you change your if statement to read if(selection <= 'a' || selection > 'h') the calculation for Neptune...

java,string,encoding,base64,long-integer

In your long2str method, change: String s = Arrays.toString(chArray); to: String s = new String(chArray); When you use Arrays.toString() you are getting a String of the form [Y, W, J, j, Z, G, V, m, Z, 2, h, ...], which is not a valid base 64 String. To get the...

c#,.net-3.5,int,long-integer,multiplying

Where does this minus from? From the integer overflow. Note that your code is equivalent to: int a = 256 * 1024 * 1024; int b = 8; int tmp = b * a; long c = tmp; Console.WriteLine(c); I've separated out the multiplication from the assignment to the...

You may use df[as.logical(with(df, ave(string, id, FUN= function(x) x[1] < 65))),] Or using data.table library(data.table) setDT(df)[, .SD[string[1L] <65] , id] ...

If you are using the version of Code::Blocks with mingw, see this answer: Conversion specifier of long double in C mingw ... printf does not support the 'long double' type. Some more supporting documentation for it. http://bytes.com/topic/c/answers/135253-printing-long-double-type-via-printf-mingw-g-3-2-3-a If you went straight from float to long double, you may try just...

c,architecture,malloc,long-integer,memory-alignment

CPUs often require that (or work more efficiently if) certain types of data are stored at addresses that are a multiple of some (power-of-two) value. This value is called the alignment of the data. For example, a CPU might require that four-byte integers be stored at addresses that are a...

Try data$id <- with(data, ave(seq_along(NUMBER), NUMBER, FUN=seq_along)) reshape(data, idvar=c('NUMBER', 'Gender'), timevar='id', direction='wide') If you want the Date.Tested variable to be included in the 'idvar' and you need only the 1st value for the group ('NUMBER' or 'GENDER') data$Date.Tested <- with(data, ave(Date.Tested, NUMBER, FUN=function(x) head(x,1))) reshape(data, idvar=c('NUMBER', 'Gender', 'Date.Tested'), timevar='id', direction='wide')...

objective-c,long-integer,nsnumber

When you compare NSNumber to other objects, you have two options that do different things: You can use == to check if two objects represent the same exact object instance, or You can use isEqual: method to check if two objects represent the same value. In your case the safest...

If you only multiply two ints you should cast them to long before multiplying. long l2 = ((long) l) * ((long) l). If l is already a long (as in your case) you do not have to cast. Integers larger than Long.MAX_VALUE can be handled with BigInteger. You can not...

c,gcc,cython,long-integer,int128

EDIT: this is NOT a workaround anymore, this is the right way to do it. Refer also to @IanH's answer. Now, the problem you have is that cython does not recognize your type, while gcc does. So we can try to trick cython. File helloworld.pyx: cdef extern from "header_int128.h": #...

java,int,progress-bar,long-integer

You could set the maximum length of your progress bar to 100, then calculate a divisor as follows: long divisor = totalSize / 100; Then each time you want to update the progress bar, simply: int progressAmount = (int)(amountCopied / divisor); ...

(See Eric's answer for more detailed explanation) Notes: Generally, int is set to the 'natural size' - the integer form that the hardware handles most efficiently When using short in an array or in arithmetic operations, the short integer is converted into int, and so this can introduce a hit...

The actual size of long isn't specified to be an exact number of bytes, only the range of values that it must be able to represent. You could however use fixed width integers std::int64_t This, along with other fixed width integer types, are available in <cstdint>...

node.js,process,exec,long-integer

Your question is basically this: You want to execute a system command via node, and capture the standard output. The best way to do that is using the child_process module: var sys = require('sys') var exec = require('child_process').exec; exec('node sample.js -mobile production', function(err, stdout, stderr) { console.log('Process finished executing!'); console.log('err:',...

oracle,spring-batch,long-integer,truncated

After much research and trials, I ended up retrieving the LONG RAW data type as a byte[]. Following is the relevant code that I wrote to retrieve the data public byte[] getALongRawText(final SomeObject someObject) { byte[] result = myJdbcTemplate.query(getALongRawTextSql, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement preparedStatement) throws SQLException {...

100000000 with 8 zeros or 1000000000 with 9 zeros fit into an 32bit int (long, not long long), and that´s the default. Then the multiplications are made with 32bit int´s, and then the result gets converted to 64bit. This is a problem because the result won´t fit into 32bit =>...

I've made a new version of the algorithm's expanation to answer to the comments. New version As input we have a 64bit integer v represented as a string of decimal digits. We need to pack it into the two's complement format. The result has two parts h and l (high...

c#,floating-point,type-conversion,long-integer

As M.kazem suggested in the comment, it was resulting in an overflow and as per C# specification compiler was silently ignoring it Console.WriteLine("float to long casting: {0}",(long)f); But if we convert above under checked then an overflow expression is thrown. checked { Console.WriteLine("float to long casting: {0}",(long)f); } ...

c++,arrays,int,long-integer,sizeof

You can't force the built-in long int type to be 4 bytes long on LP64 platforms (or stranger platforms, for that matter). However, you can use the types in <stdint.h> to guarantee the exact size of your variables. In your case you'll want either int32_t or uint32_t as your type,...

java,long-integer,integer-overflow

1 << 31 is an int, not a long. And what you have is not really an overflow, but Integer.MIN_VALUE (sign bit set, all the rest zeroes). Unless you suffix them appropriately, any numeric constant in Java is an int by default. If you want a long, you have to...

python-2.7,bytearray,long-integer

import struct struct.unpack('>l', ''.join(ss)) I chose to interpret it as big-endian, you need to decide that yourself and use < instead if your data is little-endian. If possible, use unpack_from() to read the data directly from your file, instead of using an intermediate list-of-single-char-strings....

java,random,64bit,long-integer,uuid

If you need the numbers to be unique in one process, robust between restarts, you can use a simple AtomicLong and a timer. private static final AtomicLong TS = new AtomicLong(); public static long getUniqueTimestamp() { long micros = System.currentTimeMillis() * 1000; for ( ; ; ) { long value...

The Norwegian eleven digit Birth Number is assigned at birth or registration with the National Population Register. The register is maintained by the Norwegian Tax Office. It is composed of the date of birth (DDMMYY), a three digit individual number, and two check digits. I'd be tempted to create...

java,int,type-conversion,long-integer

Casting a long to an int is done by removing the top 32 bits of the long. If the long value is larger than Integer.MAX_VALUE (2147483647) or smaller than Integer.MIN_VALUE (-2147483648), the net effect is that you lose significant bits, and the result is "rubbish". Having said that, the code...

You can write a effective program by using a string instead of long. I have used it. Here I am giving the code: #include<iostream> using namespace std; #include<string.h> int main() { char s[80]; //you can take any big index instead 80 gets(s); int a=0,l=strlen(s); for(int i=0;i<l;i++) { if(s[i]==s[l-i]) { a++;...

java,type-conversion,bit-manipulation,byte,long-integer

java's byte type is signed, so 0xff (255) == -1, during extending from byte to int/long - signed value is preserved, so if you just have code: final byte a = (byte)0xff; final long b = a; System.out.println(b); // output here is -1, not 255 so, here comes one trick:...

php,random,long-integer,uniqueidentifier

you can also try this: function random19() { $number = ""; for($i=0; $i<19; $i++) { $min = ($i == 0) ? 1:0; $number .= mt_rand($min,9); } return $number; } echo random19(); which would output some random 19 numbers: 6416113158912395605...

The maximum value of long in java is 2^63. That will safely take you up to the factorial of 20. However, factorial of 21 comes to around 2^65, so you are exceeding the maximum value that can be represented. See this question for a discussion about what happens in java...

java,arrays,long-integer,biginteger

The only real difference between a char and a long is the data size. A char is typically 1 byte, while a long is typically 8 bytes. When you convert a long to a string, you are creating an array of ASCII characters that would represent this number. For example,...

You're computing 32-bit signed ints, the computation overflows, and then you assign the result to a long. Do your calculation in 64 bits by making one of the operands a long. For example, add L to one of the operands to make it a long literal: interval = 1000L*60*60*24*30; ...

boolean,pascal,long-integer,bubble-sort,insertion-sort

In Pascal, boolean operators and and or have higher precedence than the comparison operators >, =, etc. So in the expression: while j > 0 and A[j] > key do Given that and has higher precedence, Pascal sees this as: while (j > (0 and A[j])) > key do 0...

The magnitude of the difference is not important, simply that there is a difference. long a0long = a0.getID(); long a1long = a1.getID(); if (a0long < a1long) { return -1; } return a0long == a1long ? 0 : 1; ...

java,integer,boolean,long-integer,bit

Use bitwise operators : public static void setUnlocked(int id) { unlocked |= 1L<<id; // set the id'th bit } public static boolean isUnlocked(int id) { return (unlocked & (1L<<id)) != 0; // get the id'th bit } 1<<id is the fastest way to compute 2^id. bitwise OR (|) lets you...

The thing is that numbers like 2.2278e+08, 1.2339e+09 and 6.1868e+08 are in floating-point notation and therefore cannot be parsed as long numbers directly. However you could parse them as double values doing something like long l = Double.valueOf("2.2278e+08").longValue(); Of course this departs from the assumption that you know that all...

c,string,int,long-integer,strtol

We give the algorithm, you write the code. Agree? OK, so the logic should be create an array of chars based on the end-start+1 index range. do a memcpy() from the source to the new array fro the end-start size. null-terminate the array. use strtol() to convert the array to...

java,numbers,generator,long-integer

Based on this code A[i] is equal to Factorial(i). When n=11, you calculate Factorial up to 22, and Factorial(22) is larger than the max value of long, so your calculations overflow, and the result is wrong. You can avoid the overflow is you realize that: (Array[count] / (Array[n]*Array[n])) / (n+1)...

c++,visual-c++,integer,g++,long-integer

if i start a unsigned long with 4294967295 ( his max allowed value ) 4294967295 is only the maximum value for unsigned long if unsigned long is a 32-bit type. This is the case on Windows, both 32-bit and 64-bit. On Linux, unsigned long is a 32-bit type on...

java,types,calendar,long-integer

instead of comparing hours after converting it into milliseconds you can use Date::before or Date::after methods after setting your time into two separate Date objects. Date date1 = new Date(); // set time for first hour. Date date2 = new Date(); // set time for second hour. You can use...

TL;DR --> Please use appropriate format specifiers and always check for the limit of the value that can be held by the used data type. In your code, scanf("%d",&student.id); %d is not the correct format specifier for long int. For long int it should be %ld For unsigned long int...

Try long peopleOid = it.next().longValue() (documentation)....

math.sqrt returns an IEEE-754 64-bit result, which is roughly 17 digits. There are other libraries that will work with high-precision values. In addition to the decimal and mpmath libraries mentioned above, I maintain the gmpy2 library (https://code.google.com/p/gmpy/). >>> import gmpy2 >>> n=gmpy2.mpz(99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999982920000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000726067) >>>...

r,long-integer,biginteger,bigdecimal

All your problems can be solved with Rmpfr most likely which allows you to use all of the functions returned by getGroupMembers("Math") with arbitrary accuracy. Vignette: http://cran.r-project.org/web/packages/Rmpfr/vignettes/Rmpfr-pkg.pdf Simple example of what it can do: test <- mpfr(rnorm(100,mean=0,sd=.0001), 240) Reduce("*", test) I don't THINK it has hypergeometric functions though......

As @Aru mentioned, you can do it with the SpinnerNumberModel: Long val = Long.MAX_VALUE;//set your own value, I used to check if it works Long min = Long.MIN_VALUE; Long max = Long.MAX_VALUE; Long step = 1L; SpinnerNumberModel model = new SpinnerNumberModel(val, min, max, step); JSpinner spinner = new JSpinner(model); Note...

java,arrays,type-conversion,long-integer,endianness

Concerning the efficiency, many details will, in fact, hardly make a difference. The hard disk is by far the slowest part involved here, and in the time that it takes to write a single byte to the disk, you could have converted thousands or even millions of bytes to longs....

algorithm,casting,int,type-conversion,long-integer

One simply cannot get the value back when already casted from long to int. When you are casting from long to int, you are losing some bits. So, you just can't get back those bits and can't get back your lost long value by using a generic algorithm. In a...

The long long can definitely hold this value. The problem is that the expression that you are using to compute it, i.e. 2501*2501*2501, is an int expression. The compiler computes the result using integers. This causes an overflow, because the result does not fit in 32 bits. Hence the result...

c++,long-integer,binomial-coefficients

Factorial grows really fast and even unsigned 64-bit integers overflow n! for n>20. The overflow free way to implement the binomial coefficient is to use this recursive definition: binom(n, k) = binom(n-1, k-1) + binom(n-1, k) This ensures that you get an overflow only when binom(n,k) is too large to...

java,performance,loops,for-loop,long-integer

This is how I might have written it public class IntLoopMain { public static long fib(int n) { long a = 0; long b = 1; for (long i = 0; i < n; ++i) { // note: loop counter of type long long c = a + b; a...

Your code makes a cast to long too late: by the time the cast is performed, the multiplication has been completed in 32-bit integers, predictably causing an overflow. Change the code as follows to fix the problem: // newSum should be called newProd, because you use multiplication, not addition newSum=...

c#,casting,long-integer,unsigned,idioms

ulong is not supposed to store signed integral values. Because it does not use the last bit for storing sign value of your integer. You have to use unchecked keyword to use something like this which will get you a wrap around behavior for the value string a = aaa.ToString();...

c++,codeblocks,long-integer,division

If Population_A is in the range -16 .. 16, the integer multiply and divide will result in 0. If you want floating point division results rather than converting integer values to floats, change 6 to 6.0F and 3 to 3.0F....

Just a guess: In loadInstance() you read the values from the file, so if there is a file you won't get in the init() where you set the values. To be sure there is no gamedata-file you should reset the simulator oder delete the app from the device and try...

c++,types,int,long-integer,short

According to the standard (C++11, §3.9.1/2), Plain ints have the natural size suggested by the architecture of the execution environment; the other signed integer types are provided to meet special needs. So int is the type you should use unless you have a good reason to use any other type,...

java,casting,int,long-integer,primitive-types

long is a datatype that contains 64bits (not to be confused with the Object Long!) vs. an int (32 bits), so you can't use a simple assignment from int to long. See: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html In order to see how to declare the various datatypes, you should check specifically the following table:...

android,class,view,calendar,long-integer

From Calendar Docs: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#setTimeInMillis(long) setTimeInMillis Takes a long not a Long private long data_ricevuta; public void setDataRicevuta(long data_ricevuta) { this.data_ricevuta = data_ricevuta; } public long get_data_ricevuta() { return data_ricevuta; } change your call mWeekView.setDataRicevuta(calendarioFooter.getTimeInMillis()); to mWeekView.setDataRicevuta(Calendar.getTimeInMillis()); if that works, which it should then your calendarioFooter is the wrong time.....

You could do it manual unless using Math.pow do something like this public static long powerN(int number, int power) { int result = number; while(power > 0) { result*=number; power--; } return (long)result; } ...

Please find the below results it may help you. select conv('abcdef0123456789',16,10) from dual; +--------------------------------+ | conv('abcdef0123456789',16,10) |`Use the conv function` +--------------------------------+ | 12379813738877118345 | +--------------------------------+ ...

php,mysql,optimization,long-integer

While ORDER BY rand() seems to be the major problem, it might be worth recoding the query to do a join against the sub query:- SELECT s_genre.s_id, series.stitle, series.sdesc FROM s_genre INNER JOIN series ON s_genre.s_id = series.id INNER JOIN ( SELECT a.s_id FROM s_genre a INNER JOIN s_genre b...

long-integer,logstash,kibana,ipv4

This is because 'ip' is stored internally as a number. In order to have a string version of the ip address, you need to add it to the mapping and then use ip.raw in your panel: "MY_FIELD" : { "index" : "analyzed", "type" : "ip", "fields" : { "raw" :...

c++,winapi,double,long-integer

You don't need to cast from LONG to double. You can simply write: cursor[0] = cPos.x; cursor[1] = cPos.y; ...

java,loops,for-loop,integer,long-integer

Something like this: public class Test { public static long getNumber(long input) { while(input > 101) { input = input /10; } return input; } public static void main(String[] args){ System.out.println(getNumber(101111)); System.out.println(getNumber(89123)); } } ...

java,mysql,prepared-statement,long-integer,bigint

What is the difference between BIGINT and LONG on the MySQL level? java.sql.Types.BIGINT is defined as: The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIGINT. Under Integer Types, the MySQL manual documents that its BIGINT datatype is...

c++,format,long-integer,c-strings

If this is MFC, it should be like this: CString cstr; cstr.Format("SELECT 123=%ld, 456=%ld AND type = '%s' ", 123, 456, "'type'"); It's like printf. ...

c#,converter,long-integer,strtol

You just need to add the base parameter to your call. long value = Convert.ToInt64(stringVal, base); where base is the base of the number....

php,timeout,webserver,long-integer

If you want to increase the maximum execution time for your scripts, then just change the value of the following setting in your php.ini file- max_execution_time = 60 If you want more memory for your scripts, then change this- memory_limit = 128M One more thing, if you keep on processing...

A lazy way can be to use BigInteger. BigInteger a = new BigInteger("188237574385834583453453635"); BigInteger b = BigInteger.valueOf(Long.MAX_VALUE); System.out.println("a > Long.MAX_VALUE is : " + (a.compareTo(b) > 0 ? "true" : "false")); If performance is important, you will have to test more solutions. @SotiriosDelimanolis idea is also a good one :...

objective-c,int,long-integer,nsinteger

7205759403792935 is more than 32 bits. The value is -1 as a 56 bit integer.

Change long result = (4096*4096*seconds); to long result = (4096L*4096L*seconds); in order to get a long result and avoid int overflow. 4096*4096*seconds is a multiplication of 3 ints, and results in an int, which may overflow before being assigned to your long variable....

java,postgresql,long-integer,numeric

In case of Oracle/PostgreSQL the corresponding type to NUMBER/NUMERIC is Java's BigDecimal. The both types have the same internal representation (number stored as decimal digits). So you do not face any problems with rounding errors and also casting between them should be faster. It is big misunderstanding that many Java...

c#,int,32bit-64bit,long-integer,fixed-point

The type you use is irrelevant, with regards to the platform, as types are types are types, in C#. In other words, a long is always 64 bits, no matter what platform you're on. It's a guarantee of C#. However, the real problem is going to be precision and scale.....

!! negates a boolean expression twice, essentially converting an expressions value to 0 or 1. As in C all values other than zero mean true, and zero means false, !! can be used to convert it into 0 or 1, in the case you need to use it later in...

string,parsing,date,long-integer

Use the Formatter to parse the date: DateFormat df = new SimpleDateFormat("dd/MM/yyy"); Long date = df.parse("12/12/2014").getTime(); ...

java,int,type-conversion,long-integer

Array dimensions can only be int types. The compiler is expecting that type but you are passing in a long type. You could change the argument type being passed in to an int and the make the corresponding changes. For completeness, here is what the JLS says about variables in...

long.MaxValue = 9223372036854775807 your value 1 = 18374686479671623680 your value 2 = 9259542123273814144 Your values are bigger than the signed long can hold. This is why you have to use unsigned....

c++,performance,int,long-integer,short

the 'natural size' is the width of integer that is processed most efficiently by a particular hardware. Not really. Consider the x64 architecture. Arithmetic on any size from 8 to 64 bits will be essentially the same speed. So why have all x64 compilers settled on a 32-bit int?...

If you want to REMOVE the digits, divide by 10^n: long x = 1234567890L; long removeLastNDigits(long x, long n) { return x / Math.pow(10, n); } removeLastNDigits(x, 3) == 1234567L; As pointed out by dasblinkenlight, if you want to 0 the last n digits then after removing them you need...

Overflow in scanf triggers undefined behavior. However, many popular implementations of scanf use functions from strto... group internally to convert strings into actual numbers. (Or, maybe more precisely, they use the same lower-level implementation primitives as strto... functions.) strto... functions generate max value of the target type on overflow. The...

html5,spring-boot,long-integer,thymeleaf

It depends on your model. If there is 0 and this is the default for long this will shown in the view. If the ordernumber can be null or empty you should use Long. This is only an assumption. To give you a detailed answer you must provide more information.

methods,javafx,long-integer,tablecolumn

You can use a ReadOnlyLongWrapper, which implements ObservableValue<Number> as required.

java,double,override,long-integer,hashcode

The double value is 64 bits wide but the int returned by hash method has only 32 bit. In order to achieve a better distribution of hash values (compared to simply striping the upper 32 bits). The code uses XOR to incorporate the upper 32 bits (containing sign, exponent and...

Try to fix the constructor: public LinkedLargeInteger(long largeLong) { String s = Long.toString(largeLong); head = new Node(); tail = head; size = 0; for (int i = 0; i < s.length(); i++) { // You were putting the whole number, not the digits tail.next = new Node(Long.parseLong(String.valueOf(s.charAt(i))), null); // <<==...

xcode,string,swift,long-integer,int64

(From my above comment:) If you compile as a 64-bit app then Int is a 64-bit integer.