Skip to content

Commit

Permalink
Use float to string conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Jul 1, 2024
1 parent 3fc00b1 commit 263d39b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion llamafile/server/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@ encode_json(char* p, unsigned long x) noexcept
return FormatUint64(p, x);
}

char*
encode_json(char* p, float x) noexcept
{
double_conversion::StringBuilder b(p, 256);
kDoubleToJson.ToShortestSingle(x, &b);
b.Finalize();
return p + strlen(p);
}

char*
encode_json(char* p, double x) noexcept
{
double_conversion::StringBuilder b(p, 128);
double_conversion::StringBuilder b(p, 256);
kDoubleToJson.ToShortest(x, &b);
b.Finalize();
return p + strlen(p);
Expand Down
3 changes: 3 additions & 0 deletions llamafile/server/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ encode_json(char*, int) noexcept;
char*
encode_json(char*, long) noexcept;

char*
encode_json(char*, float) noexcept;

char*
encode_json(char*, double) noexcept;

Expand Down

0 comments on commit 263d39b

Please sign in to comment.