2

I'm writing a JSON library for C (see https://github.com/DanielWaterworth/Butterfly ). I can serialize every other data type, but floating-points have stumped me. I need to write 2 functions:

  • The first takes as an argument the number (as a double) to be serialized and returns the length that the serialized string would be (minus the null terminator).
  • The second takes as arguments the number (as a double) and a buffer (which is at least as long as the output of the previous function). It then writes to the buffer and returns the length of the serialized string.

All I need is some helpful hints to get me started.

1 Answer 1

2

I have a working implementation using snprintf and asprintf. It seems that this is the technique that python's repr function used to use until they moved to a dtoa based approach. I'm still interested in other approaches.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.