Questions tagged [negative-number]

A negative number is a number that is less than 0. It is signified by a preceding hyphen (i.e. -12,345).

This tag should be used for any questions dealing specifically with negative numbers.

599 questions
8
votes
1 answer

Guaranteeing negative result when left shifting a negative number in two's complement?

Assuming a negative binary number is represented in two's complement, how can we guarantee the sign is preserved? Let's say we represent a decimal number -5 in four bits: 1011, and want to left-shift one place to multiply by 2: 1011 << 1 This…
8
votes
5 answers

Extract negative and non-negative values from an array

I need to divide an array into two arrays. One array will contain all positive values (and zeros), the other all negative values. Example array: $ts = [7,-10,13,8,0,4,-7.2,-12,-3.7,3.5,-9.6,6.5,-1.7,-6.2,7]; Negatives result…
Ripa Saha
  • 2,532
  • 6
  • 27
  • 51
8
votes
8 answers

Python: Removing negatives from a list of numbers

The question is to remove negatives from numbers. When remove_negs([1, 2, 3, -3, 6, -1, -3, 1]) is executed, the result is: [1, 2, 3, 6, -3, 1]. The result is suppose to be [1, 2, 3, 6, 3, 1]. what is happening is that if there are two negative…
user3161743
  • 161
  • 4
  • 8
  • 13
8
votes
4 answers

1000 * 60 * 60 * 24 * 30 results in a negative number

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…
NoobDev954
  • 119
  • 1
  • 3
  • 11
7
votes
2 answers

how to search negative number in solr?

In solr I want to search one field with negative number like nodeId:-1. in schema.xml, I defined it like this: solr throws error when use "nodeId:-1" to search like this: …
user1058984
  • 73
  • 1
  • 4
7
votes
2 answers

C standard on negative zero (1's complement and signed magnitude)

All of these functions gives the expected result on my machine. Do they all work on other platforms? More specifically, if x has the bit representation 0xffffffff on 1's complement machines or 0x80000000 on signed magnitude machines what does the…
tyty
  • 839
  • 5
  • 12
7
votes
2 answers

Convert a raw negative rgb int value back to a 3 number rgb value

Ok so I'm working on a program that takes in an image, isolates a block of pixels into an array, and then gets each individual rgb value for each pixel in that array. When I do this //first pic of image //just a test int pix =…
shoconinja
  • 195
  • 1
  • 3
  • 11
7
votes
2 answers

processing negative number in "accounting" format

I have dataset, which negative value is presented with a bracket around the number i.e. (10)==-10, it is in csv format, how can I process it so that R will interpret the (10) as -10? Thank you. UPDATE I know I can work it out by replacing ( as -,…
lokheart
  • 23,743
  • 39
  • 98
  • 169
7
votes
2 answers

Understanding negative steps in list slicing

I am trying to understand the following behavior and would welcome any references (especially to official docs) or comments. Let's consider a list: >>> x = [1,2,3,4,5,6] This works as expected >>> x[-1:-4:-1] [6, 5, 4] But I am surprised the…
jarm
  • 241
  • 2
  • 12
7
votes
2 answers

Negative zeros in Matlab

Basically I wanted to ask two things: Why does this happen? (negative zero in Matlab) When does this happen? I came up with this. Octave has some similarities with Matlab, so the usefulness of this feature is clear, but one of the things they…
lazary
  • 449
  • 1
  • 8
  • 17
7
votes
5 answers

Unsigned negative primitives?

In C++ we can make primitives unsigned. But they are always positive. Is there also a way to make unsigned negative variables? I know the word unsigned means "without sign", so also not a minus (-) sign. But I think C++ must provide it.
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
7
votes
2 answers

Why does right shifting -1 always gives -1 in PHP?

I am trying to figure out why if I shift the negative integer -1 I always get -1, e.g.: echo -1 >> 64; // -1 echo -1 >> 5; // -1 echo -1 >> 43; // -1 echo -1 >> 1; // -1 Whatever second operand of the right shift is given, -1 remains -1... I do…
tonix
  • 6,671
  • 13
  • 75
  • 136
7
votes
2 answers

how to convert negative hexadecimal to decimal

hi I want to know how it is possible to convert a hexadecimal negative value (to complement encoding) to decimal, easily without converting hexadecimal to binary and then multiplying each bit in by a power of 2 and sums all the value to get the…
KarimS
  • 3,812
  • 9
  • 41
  • 64
6
votes
1 answer

Using fmtlib, zero padded numerical value are shorter when the value is negative, can I adapt this behaviour?

I am using fmtlib to format strings and numeric values but I have problem with negative integers. When I pad the value with zeroes, I expect a consistent number of zero no matter the sign of the value. For instance, using a padding of 4, I would…
jeromes
  • 497
  • 5
  • 17
6
votes
1 answer

Delphi Handle in negative

I am working on a project in delphi XE5. Different Popup menus are created at run time using same function. Names are given each time to pop up using "Handle" from Tcomponent class. popupname := 'XYZ' + IntToStr(handle); On some system I get…
poonam
  • 748
  • 4
  • 19
  • 40