Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Best practices for IEEE-754 non-fintite numbers (NaN, Infinity) #346

@vmx

Description

@vmx

Do we have a FAQ-like/best practices document? I'd like to see the question: "How do I represent IEEE-754 non-finite numbers like Nan or Infinity in IPLD?

I guess the answer is something along the line of:

This is application specific. If your application is using decimal numbers, it almost certainly is using IEEE-754 floating point arithmetics. You might not even put a thought into things like Infinity or NaN and hence don't really support it. Then the right approach can be to error if you encounter those values. If you don't want to fail hard on those values, you could use null for them (if you're using IPLD Schemas, use the nullable type modifier). If you want to preserve those values, use strings (if you're using IPLD Schemas, use an enum e.g.:

type Ieee754NonFinite enum {
  | PositiveZero ("+0")
  | NegativeZero  ("-0")
  | SignallingNan ("sNaN")
  | QuietNan  ("qNaN")
  | PositiveInfinity ("+Inf")
  | NegativeInfinity  ("-Inf")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions