Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
csm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
labrobotica
algorithms
csm
Commits
c9f39ce2
Commit
c9f39ce2
authored
15 years ago
by
Andrea Censi
Browse files
Options
Downloads
Patches
Plain Diff
added option for specifying format to JSON double formatting
parent
ea3c59b7
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
sm/apps/json2matlab.c
+1
-1
1 addition, 1 deletion
sm/apps/json2matlab.c
sm/lib/json-c/json_object.c
+9
-1
9 additions, 1 deletion
sm/lib/json-c/json_object.c
sm/lib/json-c/json_object.h
+5
-0
5 additions, 0 deletions
sm/lib/json-c/json_object.h
with
15 additions
and
2 deletions
sm/apps/json2matlab.c
+
1
−
1
View file @
c9f39ce2
...
...
@@ -128,7 +128,7 @@ void jo_write_as_matlab(JO jo, FILE*out) {
fprintf
(
out
,
"%d"
,
json_object_get_int
(
jo
));
return
;
case
json_type_double
:
case
json_type_double
:
fprintf
(
out
,
"%lg"
,
json_object_get_double
(
jo
));
return
;
...
...
This diff is collapsed.
Click to expand it.
sm/lib/json-c/json_object.c
+
9
−
1
View file @
c9f39ce2
...
...
@@ -357,15 +357,23 @@ int json_object_get_int(struct json_object *this)
}
}
const
char
*
float_format
=
"%e"
;
void
json_set_float_format
(
const
char
*
f
)
{
float_format
=
f
;
}
/* json_object_double */
static
int
json_object_double_to_json_string
(
struct
json_object
*
this
,
struct
printbuf
*
pb
)
{
#define AC_BETTER_PRECISION
#ifdef AC_BETTER_PRECISION
//#warning json: Using better precision in printing floats
if
(
((
int
)
this
->
o
.
c_double
)
!=
this
->
o
.
c_double
)
return
sprintbuf
(
pb
,
"%25.18Lg"
,
this
->
o
.
c_double
);
// return sprintbuf(pb, "%g", this->o.c_double);
return
sprintbuf
(
pb
,
float_format
,
this
->
o
.
c_double
);
else
return
sprintbuf
(
pb
,
"%d.0"
,
(
int
)
this
->
o
.
c_double
);
#else
...
...
This diff is collapsed.
Click to expand it.
sm/lib/json-c/json_object.h
+
5
−
0
View file @
c9f39ce2
...
...
@@ -46,6 +46,9 @@ enum json_type {
/* reference counting functions */
/**
* Increment the reference count of json_object
* @param obj the json_object instance
...
...
@@ -307,4 +310,6 @@ extern struct json_object* json_object_new_string_len(const char *s, int len);
*/
extern
char
*
json_object_get_string
(
struct
json_object
*
obj
);
extern
void
json_set_float_format
(
const
char
*
f
);
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment