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
5
votes
3 answers

The mod of negative numbers in C

In C the following code ... #include #include #include #include int main() { int result = (-12) % (10); printf("-12 mod 10 = %d\n",result); return 0; } gives this output > gcc modTest.c >…
SA610
  • 55
  • 1
  • 6
5
votes
1 answer

How to block negative numbers on h:inputText with JSF

I´m using jsf to build a form, and I have this kind of inputtext:
Promoção:
Chico Luiz
  • 191
  • 1
  • 2
  • 8
5
votes
3 answers

Prevent user passing negative numbers to a function accepting unsigned int

So here's the code: int create_mask(unsigned b, unsigned e) { unsigned int mask=1; if(b= 0.\n"); …
zubergu
  • 3,646
  • 3
  • 25
  • 38
5
votes
4 answers

Regex pattern to match positive and negative number values in a String

I have pattern/matcher lines that transform input Strings like this: 1 3 Hi [2 1 4] into an Array like this: [0] => "1" [1] => "3" [2] => "Hi" [3] => "2 1 4" That's the code: String input = sc.nextLine(); Pattern p =…
afontcu
  • 170
  • 2
  • 12
4
votes
2 answers

Delphi - from Integer to Byte type (negative number conversion)

I tested some code: var B: Byte; I: Integer; begin I := -10; B := I; end; And I expected to see the result in the variable In the number 10 (since this is the low byte of the type integer ). But the result was B => 246. Logically, I…
DevSergo
  • 55
  • 6
4
votes
1 answer

sprintf adds minus sign to zero after rounding

Let's do some rounding > round(-0.001, 2) [1] 0 I receive zero. Now in combination with sprintf > sprintf("%f", round(-0.001,2)) [1] "-0.000000" Why is there a minus sign? I expected 0.000000. $R --version R version 2.13.1 (2011-07-08)
woobert
  • 482
  • 5
  • 14
4
votes
2 answers

When is it useful to write "0 - x" rather than "-x"?

I've occasionally noticed some C code insisting on using 0 - x to get the additive complement of x, rather than writing -x. Now, I suppose these are not equivalent for types smaller in size than int (edit: Nope, apparently equivalent even then), but…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
4
votes
2 answers

How to use order function to order negative value?

I am trying to use order function to order a column of the table, a<-c("-2","-7","-4") b<-c("9","-1","3") z<-data.frame(a,b) When I want to order Z by column a, from the largest to smallest, while it doesn't work. The function orders the…
Eva
  • 917
  • 4
  • 18
  • 23
4
votes
5 answers

Converting negative number in string to float (Python)?

Ok. I give up. I have a DataFrame with a column ("Amount") of large numbers: Amount -1 000 000,00 4 848 903,00 -2 949 234,00 13 038 023,00 7 985 232,00 .... I want to convert these to numbers that I can calculate with. Let's…
Cronos
  • 83
  • 1
  • 2
  • 6
4
votes
2 answers

How to stop Google Sheets converting numbers wrapped in parentheses to negative numbers?

I'm trying to copy a regression table into Google sheets but have encountered a problem where it converts numbers wrapped in parentheses (in this case standard errors) to negative numbers. For example (0.02) will become -0.02. I have encountered…
Tom Davidson
  • 737
  • 1
  • 8
  • 16
4
votes
1 answer

Extract positive and negative floating point numbers from a string in php

For a php I have to extract floating point numbers from a string. I'm new to regex, but I found a solution which works for me in most cases: Extract floating point numbers from a string in PHP $str = '152.15 x 12.34 x…
mischa.mole
  • 357
  • 2
  • 12
4
votes
3 answers

Python format negative currency

I haven't found anything that addresses how to format negative currency, so far, and it is driving me crazy. from decimal import * import re import sys import os import locale locale.setlocale( locale.LC_ALL, 'English_United States.1252' ) #…
Mike Sr
  • 511
  • 1
  • 5
  • 15
4
votes
3 answers

How does imul and idiv really work 8086?

I am trying to figure out how the imul and idiv instructions of the 8086 microprocessor work. I know this: 1. mul and div are multiplications and division for unsigned numbers 2. imul and idiv, are also multiplications and divisions but for signed…
user1812076
  • 269
  • 5
  • 21
4
votes
1 answer

JavaScript: greater or equal than positive zero?

Simple question: How do i test if a value is greater or equal than positive zero (+0)? Or how do I test if it's greater than negative zero (-0)? val >= 0 or val >= +0 or val > -0 don't do the trick. (I need it for handling moments.js diff() output.…
koubic
  • 597
  • 1
  • 11
  • 23
4
votes
3 answers

Modulo of a negative number

Consider the following expression: (a - b) mod N Which of the following is equivalent to the above expression? 1) ((a mod N) + (-b mod N)) mod N 2) ((a mod N) - (b mod N)) mod N Also, how is (-b mod N) calculated, i.e., how is the mod of a…
Born Again
  • 2,139
  • 4
  • 25
  • 27