Questions tagged [negative-zero]

Negative zero is a value that occurs in several representations of signed numbers, including IEEE 754 floating point formats. It usually compares equal to positive zero but may result in different results under certain operations.

Negative zero is a value that occurs in several representations of signed numbers, including IEEE 754 floating point formats and integers using ones' complement or sign-and-magnitude representation. It usually compares equal to positive zero but may result in different results under certain operations, for example with IEEE 754 floating point 1. / 0. = ∞ while 1. / -0. = -∞.

Negative zero does not exist in the common two's complement representation for signed integers.

Further details can be found in Wikipedia's article about signed zero.

28 questions
1
vote
0 answers

Why does clang not optimize away adding 0.0 to a floating-point number?

Compiling the following code with clang 14.0.0 (x86-64, -O3) double f (double x) { return x + 5.0 + 0; } results in .LCPI0_0: .quad 0x4014000000000000 # double 5 f(double): # @f(double) addsd xmm0, qword ptr [rip + .LCPI0_0] xorpd xmm1,…
FPK
  • 2,008
  • 13
  • 19
1
vote
2 answers

Negative zero int

I require a vector of integers, where I can distinguish between 0 and -0. So far i've come up with the idea of defining a new class called zero_int for this special case.. However, now I can't push both normal integers and the zero_int into the same…
Adam
  • 743
  • 1
  • 6
  • 11
1
vote
1 answer

Float division returning -0.0 instead of 0.0

I'm working on the exercises from Chapter 5 of How to Think Like a Computer Scientist, and am trying to solve the 3rd exercise: Write a function slope(x1, y1, x2, y2) that returns the slope of the line through the points (x1, y1) and (x2, y2). Be…
dan
  • 401
  • 1
  • 5
  • 10
1
vote
4 answers

Can I print -0.000 as 0.000?

printf("%.3lf\n", -0.0001); This outputs -0.000, but shouldn't it be 0.000? How can I make this print without the minus sign, i.e. 0.000 ?
0
votes
2 answers

Casting '0' to double precision, then multiple by -1 will result in negative zero

I'm trying to negate a double precision value inside jsonb data. I had to cast it to double since PG will return it as text. I found that zero value are printed as -0 Is that fine? how to fix it without "CASE WHEN"
Mahmoud
  • 456
  • 3
  • 13
0
votes
1 answer

When working with financial data in Google Sheets, why are some of my "0.00" values reporting as negative or positive?

I'm currently working with financial data and there's a lot of manual data entry. I'm using a dedicated SUM column combined with conditional formatting to double check my work. Using this number formatting: #,##0.00;(#,##0.00) I'm working with…
0
votes
2 answers

Any examples / scenarios where negative zero in JavaScript make a big difference?

I know that JavaScript has both a normal zero 0 (known as a positive zero +0) and a negative zero -0, however I have never come across a situation where I had to use -0. There are some existing posts on stack overflow about how positive and…
Aaditya Sharma
  • 3,330
  • 3
  • 24
  • 36
0
votes
2 answers

Handle -0 from Database Value in C++

At present I am working on piece of C++ code in which I need to read data from a database, and if database value is non-zero, then I need to apply some further logic. But in the database there are values which are being calculated and can come out…
WENzER
  • 205
  • 1
  • 5
  • 15
-1
votes
1 answer

can you store negative zero in MongoDB?

In javascript, there is such thing as negative zero. What will MongoDB do with this value?
-1
votes
2 answers

Long Representation vs Double representation of positive and negative zero in java

I was wondering about the differences between positive and negative zero in different numeric types. I understand the IEEE-754 for floating point arithmetic and bit representation in double precision so the following didn't come as a…
Mr T.
  • 4,278
  • 9
  • 44
  • 61
-2
votes
1 answer

php how to avoid negative answer

Hi I am a newbe and writing a simple code for tax purposes. So far I have wrote a small code but I think there seems to be a problem with the function taxable_i($i) which is not letting me make $taxable_i NIL. I have tried everything. When I try to…
-3
votes
1 answer

Why does −0 convert to the string "0"?

When dealing with floating-point numbers, −0 is a different number from 0. I am building a timer application in JavaScript and apparently found out the hard way when converting the number of minutes into a string. For any other number of minutes…
azoundria
  • 940
  • 1
  • 8
  • 24
-3
votes
1 answer

How to remove negative Zeros from c++ codes?

How to remove "negative zero" in c/c++? I am trying this- #define isEq(a, b) ((abs(a-b)
NAbdulla
  • 85
  • 7
1
2