GithubHelp home page GithubHelp logo

CborFloat about cbor HOT 3 CLOSED

shamblett avatar shamblett commented on July 21, 2024
CborFloat

from cbor.

Comments (3)

shamblett avatar shamblett commented on July 21, 2024

The reason that this has not been implemented thus far is that the CBOR spec(RFC's 8949 and 7049) have an expectation that the most efficient form of encoding should be used if possible, for floats for instance from the spec -

If a protocol allows for IEEE floats, then additional
   canonicalization rules might need to be added.  One example rule
   might be to have all floats start as a 64-bit float, then do a test
   conversion to a 32-bit float; if the result is the same numeric
   value, use the shorter value and repeat the process with a test
   conversion to a 16-bit float.  (This rule selects 16-bit float for
   positive and negative Infinity as well.)  Also, there are many
   representations for NaN.  If NaN is an allowed value, it must always
   be represented as 0xf97e00.

That said I don't thinkmits unreasonable to allow users to chose how floats are encoded if they wish to do so.I'll have a look at this and see what can be done.

from cbor.

shamblett avatar shamblett commented on July 21, 2024

Ok you can now do this with floats -

 final encoded = cbor.encode(CborFloat(0.0)..halfPrecision());

Similar for float and double precision. If the value supplied cannot be represented in the specified precision an ArgumentError is thrown.

Package re released at version 5.1.0

from cbor.

shamblett avatar shamblett commented on July 21, 2024

Forgot to add, if you dont specify a precision you get current behaviour i.e. best fit.

from cbor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.