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
-3
votes
1 answer

Is it possible to display more detailed Function() info during debugging

I have an issue random number generating. I've made an AI for game "Guessing number game" and it works just fine until the Player hit number lower than searched number. After that Math.random(); may and it is very likely to generate negative…
Luke_Nuke
  • 461
  • 2
  • 6
  • 23
-3
votes
2 answers

Example of graph with negative weights that Dijkstra's Algorithm will work correctly

This is not another duplicate of question, trying to understand, why Dijkstra can't work with negative weights. I know why, but in some special case's, it will work with negative weights and I'm trying to found them. So, in some case, Dijkstra can…
TheColloto
  • 31
  • 8
-3
votes
2 answers

Matlab can not set to negative, -1

I want to replace certain values in matrix/vector to -1, but can't seem to be able to. x = [1 5 6; 2 4 3; 3 4 2; 4 2 1]; z = x(:,1) == 4 % get result I want z = 0 0 0 1 changem(z,-1,0) % changem doesn't work ans = 1 1 1 1 same if I make…
h1vpdata
  • 331
  • 2
  • 15
-3
votes
1 answer

Addition and Subtraction with Negative Numbers

I tried adding and subtracting negative numbers with this code var num1 = parseInt(document.form1.num1.value); var num2 = parseInt(document.form1.num2.value); if(operand == "plus"){ var sum = parseInt(num1+num2); // add alerts to check …
Hikmah Az
  • 27
  • 1
  • 1
  • 6
-3
votes
3 answers

Project euler 10 help. Whats wrong with this code? the sum flips to negative

// finding sum of all primes under 2 million public class lll { public static void main(String[] args) { int a = 2; int b = 0; int c = 0; while (a < 2000000) { int i = 1; for (i = 1; i * i…
Iexist
  • 53
  • 1
  • 7
-3
votes
5 answers

why negative number is taken as true in condition statement?

Here i am confused with condition statement which has negative number,if in the condition only negative number is given as if(-1) then it is true but if (-1>0) then it become false please explain any one thanks in advance if(-1) // This true why…
BECOOL
  • 203
  • 1
  • 3
  • 11
-4
votes
3 answers

Why does Java and Javascript Math.round(-1.5) to -1?

Today, I saw this behaviour of Java and Javascript's Math.round function. It makes 1.40 to 1 as well as -1.40 to -1 It makes 1.60 to 2 as well as -1.60 to -2 Now, it makes 1.5 to 2. But, makes -1.5 to -1. I checked this behaviour in round…
Sujit Singh
  • 921
  • 1
  • 10
  • 20
-4
votes
3 answers

Ruby, making a number negative

This is probably super basic, but I've tried enough things that have failed to reach out.. I want to change a number to it's negative version. answer = [] array = [3, 5, 2, 19, 2, 1] array.each.with_index do |x, i| if x > array[i+1] …
Viola Crellin
  • 61
  • 2
  • 8
-4
votes
7 answers

How do I find the largest negative value in an array with both positive and negative values?

I need to return the greatest negative value, and if there are no negative values, I need to return zero. Here is what I have: public int greatestNegative(int[] list) { for (int i = 0; i < list.length; i++) { if (list[i] < 0) …
-4
votes
4 answers

Numbers positive and negative

What am i doing wrong? I want to have a random numbers. Negative and positive integers #include #include int main(){ int a; cin<
Antua
  • 185
  • 9
-4
votes
2 answers

How do I not allow negative numbers?

public boolean add(int v) { if (count < list.length) // if there is still an available slot in the array { if (v >= minValue || v <= maxValue) // if the value is within range { …
user2317726
  • 1
  • 1
  • 2
-5
votes
3 answers

python: grading assignment, negative value

I am working on a python lettering assignment. 90 or above is an A and so on and so on for the rest of the letter grades; but when a value is inputted as a negative number, I need the code to do nothing other than display an error. This is what i…
-6
votes
2 answers

Is there a way computer can have same representation for two different numbers?

I have this number -16777216 in Int32 and its hex representation is FF000000. On right shifting this number right by 24 I get 0xFFFFFFFF and on masking by 0xFF000000 and then shifting right by 24 I get 0x000000FF. Int32 a = -16777216;//FF000000 in…
-11
votes
1 answer

What happens when bitwise AND is applied to negative numbers?

I have written and compiled the following code: void main() { printf("%d", -10 & 5); }
1 2 3
39
40