Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6381591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:24:48+00:00 2026-05-25T02:24:48+00:00

I want to serialize a floating point in such a way that sign info

  • 0

I want to serialize a floating point in such a way that sign info is not lost. Specifically, I would like to distinguish IEEE-754 negative zero from regular zero.

The language spec says

The result of a floating-point division by zero is not specified beyond the IEEE-754 standard; whether a run-time panic occurs is implementation-specific.

which suggests that I cannot do

n == 0 && (float64(1) / n) < 0

and I tried math.Copysign and math.Signbit which says

func Signbit(x float64) bool

Signbit returns true if x is negative or negative zero.

but

n == 0 && math.Signbit(n)

doesn’t seem to work for

n := -float64(0)

Any ideas?

EDIT:

I filed issue 2196 to track what I think is a confusing difference between

nz := -float64(0)

and

pz := float64(0)
nz := -pz

as suggested by peterSO.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:24:48+00:00Added an answer on May 25, 2026 at 2:24 am
    package main
    
    import (
        "fmt"
        "math"
    )
    
    func main() {
        pz := float64(0)
        nz := -pz
        fmt.Println(pz, math.Signbit(pz), nz, math.Signbit(nz))
        if n := nz; n == 0 && math.Signbit(n) {
            fmt.Println("n is negative zero:", n)
        }
    }
    

    Output:

    0 false -0 true
    n is negative zero: -0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to serialize a class to xml and store that in a field
I want to Serialize a class that's part of inheritance. I'm using C++98 and
I've got a class that serializes data. I may want to serialize this data
I want to serialize an object as xml that contains other custom classes. From
I want to create a class that I want to serialize as XML using
I am new to MongoDB and want to serialize my object efficiently. That means
I have a class that I want to serialize to xml. The class looks
I have a f# library with some values that I want to serialize in
I want to serialize some objects into Json. Sometimes (not always, and I don't
I want to serialize an EF model like this TableA theObject = db.TableA.find(uid); XmlSerializer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.