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
12
votes
2 answers

Why does double.IsNegative(double.NaN) return true?

Why does double.IsNegative(double.NaN) unexpectedly return true whereas double.NaN < 0 returns false as expected?
tiger-empire
  • 125
  • 6
12
votes
7 answers

How to turn all numbers in a list into their negative counterparts?

I am trying to turn a list of positive numbers into a list of negative numbers with the same value in python 3.3.3 For example turning [1,2,3] into [-1,-2,-3] I have this code: xamount=int(input("How much of x is…
user3368627
10
votes
6 answers

Are hexadecimal numbers ever negative?

Are hexadecimal numbers ever negative? If yes then how? For binary you would have signed and unsigned. How would one represent them in Hex? I need this for a hex routine I am about to embark upon.
phoenix
  • 3,531
  • 9
  • 30
  • 31
10
votes
1 answer

Stacked bar charts using python matplotlib for positive and negative values

I am trying to plot a stacked bar chart with python Matplotlib and I have positive and negative values that I want to draw. I have had a look at other posts talking about how to plot stacked bar charts with positive and negative values, but none of…
Juwairia
  • 101
  • 1
  • 1
  • 5
10
votes
3 answers

Distinguish zero and negative zero

I have run into a situation in my code where a function returns a double, and it is possible for this double to be a zero, a negative zero, or another value entirely. I need to distinguish between zero and negative zero, but the default double…
Dan Brenner
  • 880
  • 10
  • 23
10
votes
4 answers

Integer division & modulo operation with negative operands in Python

Questions arise when I type in these expressions to Python 3.3.0 -10 // 3 # -4 -10 % 3 # 2 10 // -3 # -4 10 % -3 # -2 -10 // -3 # 3 It appears as though it takes the approximate floating point (-3.33)? and rounds down either way in integer…
tlands_
  • 176
  • 1
  • 10
10
votes
7 answers

Detecting and adjusting for negative zero

I have some code that has been port from Java to C++ // since this point is a vector from (0,0,0), we can just take the // dot product and compare double r = point.dot(normal); return (r>=0.0); But in C++ r can be either +0.0 or -0.0, when r equals…
Justin
  • 4,196
  • 4
  • 24
  • 48
9
votes
3 answers

Quick way to check if the pandas series contains a negative value

What is the quickest way to check if the given pandas series contains a negative value. For example, for the series s below the answer is True. s = pd.Series([1,5,3,-1,7]) 0 1 1 5 2 3 3 -1 4 7 dtype: int64
Krzysztof Słowiński
  • 6,239
  • 8
  • 44
  • 62
9
votes
2 answers

Is there a functional difference between "x = -x" and "x *= -1" when negating values?

Code example: float f = 123.456; int i = 12345; // negate by changing sign i = -i; f = -f; // negate by multiplying with -1 i *= -1; f *= -1.0f; Apart from aesthetics, is there any factual reason why one should prefer one way over the other? To me…
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
9
votes
6 answers

how to change negative sign position css

I have a web site that shows its content it two direction. rtl & ltr. When page is in ltr content mode, every thins is OK and the negative sign shows in the left of number. body { direction: ltr; } For example: -1 But when page is in rtl…
Tavousi
  • 14,848
  • 18
  • 51
  • 70
9
votes
1 answer

Why doesn't my Haskell function accept negative numbers?

I am fairly new to Haskell but do get most of the basics. However there is one thing that I just cannot figure out. Consider my example below: example :: Int -> Int example (n+1) = ..... The (n+1) part of this example somehow prevents the input of…
Jonathan Pike
  • 93
  • 1
  • 3
9
votes
4 answers

Change NSNumberFormatter's negative format from (xxx.xx) to -xxx.xx

I want to change my NSNumberformatter from displaying negative numbers with parenthesis around them to putting the minus sign in front (or whatever the localized standard is). I would assume I could do this with setNegativeFormat: but reading…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
8
votes
3 answers

Are process ids non-negative in Linux?

I am implementing a syscall that is called in user-space, lets say by foo. The syscall accesses foo's task_struct ( throught the global pointer current), prints it's name and pid, then goes on to foo's parent-process, foo's parent's parent etc.…
Plazo
  • 81
  • 1
  • 1
  • 4
8
votes
4 answers

Why can cosine similarity between two vectors be negative?

I have 2 vectors with 11 dimentions. a <- c(-0.012813841, -0.024518383, -0.002765056, 0.079496744, 0.063928973, 0.476156960, 0.122111977, 0.322930189, 0.400701256, 0.454048860, 0.525526219) b <- c(0.64175768, 0.54625694, …
Robin
  • 81
  • 1
  • 1
  • 2
8
votes
2 answers

Replacing negative values in a model (system of ODEs) with zero

I'm currently working on solving a system of ordinary differential equations using deSolve, and was wondering if there's any way of preventing differential variable values from going below zero. I've seen a few other posts about setting negative…
Dorian
  • 83
  • 5