FAQ Database Discussion Community


Understanding long division algorithm

algorithm,long-integer
I founded some long division code in SphinxAPI class for PHP which divides 64 bit int into two 32 bit integers and used on 32-bit machine when bc library is not available: // x32, no-bcmath $p = max(0, strlen($v) - 13); $lo = abs((float)substr($v, $p)); $hi = abs((float)substr($v, 0, $p));...

Java: Efficiently converting an array of longs to an array of bytes

java,arrays,type-conversion,long-integer,endianness
I have an array of longs I want to write to disk. The most efficient disk I/O functions take in byte arrays, for example: FileOutputStream.write(byte[] b, int offset, int length) ...so I want to begin by converting my long[] to byte[] (8 bytes for each long). I'm struggling to find...

Java long is calculated wrongly

android,long-integer
Consider this piece of code: // calculate age of dog long interval = 1000*60*60*24*30; int ageInWeeks = Weeks.weeksBetween(geburtsDatumDateTime, nowDateTime).getWeeks(); if (ageInWeeks < 20){ // wöchentlich interval = 1000*60*60*24*7; } else if (ageInWeeks >= 20 && ageInWeeks < 52){ // 2-wöchentlich interval = 1000*60*60*24*14; } else if (ageInWeeks >= 52){ //...

the usage of the long double

c,casting,double,long-integer
The functions purpose is to calculate the square root of a number using the Newton-Raphson method. I included a printf routine in the while loop so I can see the value of root 2 get closer and closer to the actual value. I originally used float to define epsilon but...

What is meant by the most restrictive type in C?

c,architecture,malloc,long-integer,memory-alignment
The book The C Programming Language talks about "the most restrictive type" in section 8.7, Example — A Storage Allocator: Although machines vary, for each machine there is a most restrictive type: if the most restrictive type can be stored at a particular address, all other types may be also....

Strange bug with Catalan number generator

java,numbers,generator,long-integer
I'm trying to write a iterative catalan number generator as opposed to a recursive one. It works, but only up until the number "10", and then it starts to print out numbers that don't make sense. Here's what I have so far. public static long dpr1(int n) { long []...

Using the sqrt function of math module for long numbers in python

python,long-integer
I was working with numbers of 200 digits in python. When finding the square root of a number using math.sqrt(n) I am getting a wrong answer. In[1]: n=9999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999998292000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000726067 In[2]: x=int(math.sqrt(n)) In[3]: x Out[1]: 10000000000000000159028911097599180468360808563945281389781327 557747838772170381060813469985856815104L In[4]: x*x Out[2]:...

long not enough to store an integer

java,long-integer
public class SDO { public static void main(String args[]) { SDO sdo = new SDO(); System.out.println(sdo.amountOfData(1)); System.out.println(sdo.amountOfData(86400)); } public long amountOfData(int seconds) { long result = (4096*4096*seconds); return result; } } This code is returning in my test, error: amountData(1000) expected:<16777216000> but was:<-402653184>. Shouldn't type long store even higher integers?...

What is the error in multiplication of long long Integer?

c,long-integer
#include<stdio.h> int main() { long long int t=8*9*100000000;// 8 zeros printf("%lld\n",t); return 0; } gives result: -1389934592 #include<stdio.h> int main() { long long int t=8*9*1000000000; //9zeros printf("%lld\n",t); return 0; } gives result: -1014444032 while all other multiplication gave correct result i.e. #include<stdio.h> int main() { long long int t=8*9*10000000000;...

Multiplying int with long result c#

c#,.net-3.5,int,long-integer,multiplying
Wonder why. C# .Net 3.5 int a = 256 * 1024 * 1024; int b = 8; long c = b * a; Console.WriteLine(c);//<-- result is -2147483648 Where does this minus from?...

Android pass long value to class View

android,class,view,calendar,long-integer
I'm using the library WeekView When the application starts, I want to pass to class View the date from calendar for set the first day of view. In the Activity, I set the calendar, and pass it to class: calendarioFooter.add(Calendar.DATE,1); mWeekView = (WeekView) rootView.findViewById(R.id.weekView); mWeekView.setOnEventClickListener(this); mWeekView.setEmptyViewClickListener(this); mWeekView.setMonthChangeListener(this); mWeekView.setEventLongPressListener(this); mWeekView.setDataRicevuta(calendarioFooter.getTimeInMillis()); In...

Java, detect whether a String beyond Long type value boundary

java,long-integer
Given following Java codes: String columnValue = "188237574385834583453453635"; columnValue =(Long.parseLong(columnValue)>Long.MAX_VALUE?"0":columnValue); It throws java.lang.NumberFormatException since the input value is beyond Long's maximum value. However, it there an easy way to detect whether a number in a 'string' type get out of Long's maximum value with out using try catch solution?...

Cast double to unsigned long C++

c++,casting,double,long-integer,unsigned
Im working on a program for homework and so far everything prints out correctly except for the planet "Neptune". Every other choice works fine and prints out the numbers as they are supposed to be but Neptune prints out the right numbers but as negatives. I have been told to...

Converting bytes to a long: Why do some implementations bitwise-AND each byte with 0xff?

java,type-conversion,bit-manipulation,byte,long-integer
I'm looking at the implementation of java.io's DataInputStream.readLong() in SE6: private byte readBuffer[] = new byte[8]; public final long readLong() throws IOException { readFully(readBuffer, 0, 8); return (((long)readBuffer[0] << 56) + ((long)(readBuffer[1] & 255) << 48) + ((long)(readBuffer[2] & 255) << 40) + ((long)(readBuffer[3] & 255) << 32) + ((long)(readBuffer[4]...

How does int(or long long) overflow in c++ affect modulus?

c++,long-integer,modulus,integer-overflow
Suppose I have two long longs, a and b, that I need to multiply, then get the value mod k for some large k, such that a, b, and k are all in the range of long long but not of int. For simplicity, a, b < k. Thus the...

How to prevent timeout when running a time consuming PHP

php,timeout,webserver,long-integer
I use PHP that gets so many data from several sites and write those data to the server which make files greater than 500 MB, but the process fails in between giving a 500 INTERNAL ERROR, but to adjust the timeout time of the php so that the process runs...

Thymeleaf HTML5 long variable issue

html5,spring-boot,long-integer,thymeleaf
I am new to Thymeleaf and HTML5. I have a variable order number of data type long. There is an input text field in the HTML for searching order number (assigned to order number variable), which always initialise to zero everytime when we load the HTML page. Also, I am...

In which type of variable store time in millis? Choosing a correct data type

java,types,calendar,long-integer
in Java I'm trying to compare two different hours by converting them to milliseconds if (20:00 > 19:30) // do anything. In millis, it would be if (72000000 > 70200000) // do anything But the smartphone doesn't do it well. I'm storing the numbers in variables long, as in the...

Online judge Rejecting My Answer

c++,long-integer,palindrome
The Next Palindrome The below code is the solution to this problem A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than...

C get numeric value from part of string

c,string,int,long-integer,strtol
My task is to get long numeric value from part of char[], where I have the index of its begining and ending. I am just learning C, so it is confusing to me which function works the best in my case.. Lets say im making function getNum(): static char words[100000];...

How to create a 64 bit Unique Integer in Java?

java,random,64bit,long-integer,uuid
I need to create a 64 bit Unique Integer in Java so that collision chances are pretty less. Is there any way, we can create a 64 bit integer in Java which is always Unique? As of now I am using - long number = System.nanoTime(); Is this the right...

Using int, double and long in calculation of powers

java,int,double,long-integer
I'm having trouble figuring out when to use int, double and long. I'm working on calculating the power of an integer and return the result as long as the power provided is not a negative number. For the assignment, I'm required to use the following code to start: public static...

Why don't loops take long as a valid type in its conditions?

java,loops,netbeans,long-integer
I am working on some Project Euler exercises and need to use extremely large numbers. I still need to use some basic loops like for-loops or while loops. My IDE ,Netbeans, is giving me an error I can't wrap my head around. long l = 10000000000L; while (l<10000000000000){ } for...

Java how to remove last numbers of a long?

java,timestamp,long-integer
i'm working with a query to bring data acording to a given time. so i want to grab a timestamp an remove the last 3 digits of it. Is it possible? how? give me a hint i will totally apreciate that

Long or String for Norwegian birth number [duplicate]

java,string,long-integer
This question already has an answer here: Integer vs String in database 14 answers I have a class called Person, which looks something like this: public abstract class Person { private String birthNo; ... } Norwegian birth numbers are 11 digits long, and are constructed from an algorithm described...

Trouble setting long value in singleton IOS

ios,singleton,long-integer
I'm having trouble with setting and accessing long properties on a Singleton object. Every time I try to access a long property it returns -1. My singleton interface file is as follows: @interface gameData : NSObject <NSCoding> @property (assign, nonatomic) long score; @property (assign, nonatomic) long level; @property (assign, nonatomic)...

Read long integers from txt in java

java,long-integer
I have a list of long integers in a text file. I want to read those numbers to long arraylist in java. Out numbers are stored in the file: 2.2278e+08 1.2339e+09 6.1868e+08 My code to read those long numbers are the following: for (String line : Files.readAllLines(Paths.get("ids.txt"))) { ids.add(Long.parseLong(line, 10));...

How to handle a 32 digits numeric in Java and PostgreSQL?

java,postgresql,long-integer,numeric
I'm developing a little tool with JavaFX and a PostgreSQL-database. My task now is to handle a 32 digits numeric. I tried it with Long, but its to short / small. I remember that Postgres grumbled because I didn't use the correct datatype, that's why I'm asking here first, before...

What's wrong with the following arithmetic operation? C++ [duplicate]

c++,codeblocks,long-integer,division
This question already has an answer here: What is the behavior of integer division in C? 5 answers I'm just trying to do a simple arithmetic operation but it returns me the 0 value. Here's the code: main(){ long Population_A, Population_B; cin>>Population_A; cin>>Population_B; float Increase_A, Increase_B; Increase_A = (6*Population_A)/100;...

Java: why the “long” primitive type does not accept a simple number?

java,casting,int,long-integer,primitive-types
I got a method that receives a long type parameher, and I try to call it passing 1: contato.setId(1); And I receive this: The method setId(Long) in the type Contato is not applicable for the arguments (int). But, isn't 1 a long number as well? Isn't it inside the long...

How to append L to variable name

java,long-integer
Say I have this variable: long l = 2000000000; I then want to create a new variable long l2 = l*l; This would not return the proper value as l*l is just too large. I know I have to append L to those very very big long numbers, but how...

different values for NSNumber long in Objective-C

objective-c,long-integer,nsnumber
I have a variable which is a NSNumber of type long. It should hold the value -1. When I log it to the Console it shows the expected value -1. NSLog(@"myVariable %@", self.myVariable); But the following expression in the if-clause is false. if (myVariable == [NSNumber numberWithInt:-1]) { ... }...

Convert a hex number in a varchar column to unsigned nteger?

mysql,long-integer
I have a table with a column hexval containing varchar(16) values like abcdef0123456789 deadbeefcafe0000 fffffffffffffff0 0000000000000000 Is there a way, using MySQL, to say SELECT convert(hexval) to 64-bit unsigned integer FROM table which will return a numeric result rather than a text string? If not for 64-bit numbers, how about...

Populate javafx tablecolumn with object method call type long

methods,javafx,long-integer,tablecolumn
Sorry for the newbie question but how do you populate a javafx table column, afaik a ReadOnlyNumberWrapper does not exist. @FXML private TableColumn<RelationshipBO, Number> tcIncomingNodeId tcIncomingNodeId.setCellValueFactory( (CellDataFeatures<RelationshipBO, Number> cellData) -> new ReadOnlyNumberWrapper(cellData.getValue().getNodeId()) ); getNodeID rturns a long Thanks a lot and best regards === Edit: Seems like I can use...

Bug (??) in formatting long values with CString::Format

c++,format,long-integer,c-strings
I have issues with the following code: CString cstr; cstr.Format("SELECT foobar %ld, %ld ", " AND type = '%s' ", 1426233870,1426243870, "'OR'"); The resulting CString contains wrong numbers! The code is simplified, actually I am selecting datasets from a database between two timestamps in seconds. I was able to solve...

Intellij long “integer value is too big” but in range of long.maxvalue

intellij-idea,javac,long-integer
This might be a silly thing but how is this possible that compiler will show this while Long.Max = 9223372036854775807 ?...

long data - remove all rows when first value for each person =X R

r,long-integer
I have a long data frame similar to below. I want to restrict the dataframe to people who were aged <65 yrs on their first observation. Note sue turns 65 during the course of the study, I don't want to remove any of her data. This is because her first...

Converting from a char to a long

java,arrays,long-integer,biginteger
I'm creating a big integer class. I read in two longs as function arguments and what I want to do is have each number in the long read in to occupy one index of an array. I've done this by converting the long into a string then char array and...

transform a dataframe from long to wide in r, but needs date transformation

r,long-integer,reshape
I have a dataframe like this (each "NUMBER" indicate a student): NUMBER Gender Grade Date.Tested WI WR WZ 1 F 4 2014-02-18 6 9 10 1 F 3 2014-05-30 9 8 2 2 M 5 2013-05-02 7 9 15 2 M 4 2009-05-21 5 7 2 2 M 5 2010-04-29...

Why does long long in c++ does not hold 2500^3 [duplicate]

c++,long-integer
This question already has an answer here: long long in C/C++ 4 answers #include <iostream> using namespace std; int main() { long long a=2501*2501*2501; cout<<a; return 0; } I tried unsigned long long too and all the time it gives some gibberish answer. I checked the capacity of long...

Can not convert long to long in Eclipse [closed]

java,eclipse,long-integer
During the implementing of a Java project, I encountered a weird error. When I try to cast long value to long I get the error - "Can not convert Long to long". The code fragments are given below. ObjectsIterator it = castFromBoth.iterator(); while (it.hasNext()) { long peopleOid = (long)it.next(); g.getAttribute(peopleOid,...

How to get Long 19 digits random numbers at PHP?

php,random,long-integer,uniqueidentifier
So I need to make unique purchase number of mobile game. Each user's buying of in-app-purchase item record should be attached by unique long type 19 digits numbers from php code and stored to mysql DB. But how can I actually make random 19 digits numbers? I tried like this...

Recover long from int after precision loss

algorithm,casting,int,type-conversion,long-integer
I inherited an application that took 2281534395476 and incorrectly casted it to an integer of 906761300. I'm looking to essentially un-cast it back to its proper and correct (long) data type. What is a reproducible algorithm for doing so that could be run over a list? I'm looking for pseudocode...

HashCode calculation from double

java,double,override,long-integer,hashcode
In Effective Java there is an example of Complex class. That class has overridden hashCode which uses hashDouble method I have a question about. private int hashDouble(double val) { long longBits = Double.doubleToLongBits(re); return (int) (longBits ^ (longBits >>> 32)); } For what purpose it does (int) (longBits ^ (longBits...

C++ unsigned long doesn't wrap around after 4294967295

c++,visual-c++,integer,g++,long-integer
I was playing with some c++ code, and found that if I start a unsigned long with 4294967295 (its max allowed value) and add let's say 6 I MUST get 5, and it does! but the following operation of addition, and mod 255 does not give the correct answer. why...

Kibana3: long to IP in terms panel

long-integer,logstash,kibana,ipv4
For an ELK(Kibana is v3) setup I feed logs from some firewalls and src_ip/dst_ip fields are defined as type "ip". eg. "dst_ip" : {"type" : "ip"} Mappings are also correct: curl -XGET http://localhost:9200/logstash-2015.03.10/_mapping/field/src_ip?pretty { "logstash-2015.03.10" : { "mappings" : { "screenos" : { "src_ip" : { "full_name" : "src_ip", "mapping":{"src_ip":{"type":"ip"}}...