22

In Go I had a bug in a sort.Interface implementation based on floating point divisions. This question's answers put me on the right track of finding my solution, but it did not answer my question directly: "How are float NaNs sorted [in Go]?"

Difficulties arose in finding the answer, because:

Floating-point values are comparable and ordered, as defined by the IEEE-754 standard.

  • The IEEE-754 standard itself is behind a paywall. I don't consider it worth the investment, as I'm not writing the compiler here. I just want to know how NaN is handled in Go.

Finally I got to a reasonable explanation in the GNU libc documentation. It is not Go documentation, but after trying it out it does work the same and it solves my question.

My meta question:

I feel inclined of posting my findings somewhere on this site, sharing this info with others that might be facing the same problem. I'm thinking of the following possibilities:

  1. Post another answer, only with the subject of comparability.
  2. Post another answer and also explain my sorter problem in the answer to justify why I'm party crashing while the other answers already suffice for the question.
  3. Ask a new question plus answer.

My considerations at the moment:

  • The answer might not directly answer the question, it is just related to it.
  • Comparability is part of the answer to my question. The linked question helped me find the answer. Would this make the new question a duplicate?
6
  • 2
    There is a lot of information available about the standard, you could start at the wiki page but it's all over the web, including typically free drafts. SO/SE search is bad, use google with 'site:', and google re advanced google searching. PS Please research before posting on any site, including this one. If you post, summarize your searching & findings.
    – philipxy
    Commented Oct 7, 2020 at 23:14
  • 2
    The title was hilarious! How could you ever doubt if you should post an answer or a question? :D (And yes, I read the rest and understood what you meant)
    – klutt
    Commented Oct 9, 2020 at 9:39
  • @klutt, with how often people want to close a question for being a duplicate and downvote for the same reason, it's definitely worth taking the time to wonder if it's worth the time, effort, and even RP. Arguing over why it's a different question and the answer won't be relevant to other threads can take a lot of time and muddy the waters of it being useful to the site. Especially if you have to take half the Question to say why it's not a duplicate to avoid fly-by DVs and close votes. Commented Oct 9, 2020 at 15:55
  • @computercarguy I think you missed my point.
    – klutt
    Commented Oct 9, 2020 at 15:59
  • @klutt, you asked a question. I answered it. And I did it in a way that questions why you even asked your question. Maybe you missed my point. Commented Oct 9, 2020 at 16:01
  • @computercarguy My question was not serious. My point was that wondering if you should post an answer or a question is like wondering if you should eat or drink. You eat if you're hungry and drink if you're thirsty, and ask a question when you want to know something you don't know and answer if you want to share knowledge you already possess.
    – klutt
    Commented Oct 9, 2020 at 16:51

3 Answers 3

36

Ask a new question. People search for answers on specific questions. Nice to stumble over an answer indirectly, but finding it in a thread related directly to the problem will be of more use. You might additionally link your question/self-answer in the one you found originally as a comment.

2
  • Agree... and this meta question already contains pretty decent question ("How are float NaNs sorted [in Go]?" with research shown) Commented Oct 7, 2020 at 22:30
  • I agree with asking a new question. I also search for answers to very specific questions, but hardly ever find an answer in a related thread (I rarely even bother). If I don't at first find an appropriate answer to my question I generally reword my Google/SO phrase and find something more relevant that way.
    – Justin F
    Commented Oct 9, 2020 at 20:43
4

Did existing Q&As like What is the rationale for all comparisons returning false for IEEE754 NaN values? not indirectly answer your question? e.g. a sort based on the < comparison predicate will find it false for all NaNs, finding they're not "less than" any other number (because the comparison result is unordered), and presumably sort them after +Inf.

That's enough logic / deduction (and details of Go's default sorting) that it's probably worth posting a Q&A to explain that, especially if you want to write it up in any more detail than I did, if there isn't an exact duplicate.

Other Q&As closer to what you're looking for:

What is the result of comparing a number with NaN? is a C++ question; the answers cover C++ implementations that follow IEEE-754 (i.e. essentially all modern ones, e.g. that compile to asm for CPUs with hardware FPUs.) I just added floating-point / ieee-754 / nan tags to make it easier to find.

Also various NaN-sorting Q&As for other languages, such as sort function breaks in the presence of NaN, except when it doesn't for Python

0

Ask a new question, tag it with all of the correct tags (go, nan, floating-point, sorting), provide as much detail as you can in order to allow someone to answer, then give it a day or two for someone else to answer before posting your own.

Self answered questions, as well as questions where you already know the answer, are both perfectly fine, as long as they are useful — don’t post a duplicate question and then self answer. The point of the site is to serve as a reference, a reference where the answer exists, but you can’t find it, is less useful than a reference where you can find the answer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .