Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NuttX RTOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
f4grx
NuttX RTOS
Commits
06871729
Commit
06871729
authored
12 years ago
by
Gregory Nutt
Browse files
Options
Downloads
Patches
Plain Diff
Support for printing NaN and infinity from Andrew Tridgell
parent
504b25ee
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libc/stdio/lib_libdtoa.c
+40
-3
40 additions, 3 deletions
libc/stdio/lib_libdtoa.c
with
40 additions
and
3 deletions
libc/stdio/lib_libdtoa.c
+
40
−
3
View file @
06871729
...
...
@@ -44,6 +44,8 @@
* Included Files
****************************************************************************/
#include
<math.h>
#include
"lib_internal.h"
/****************************************************************************
...
...
@@ -84,6 +86,10 @@
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: zeroes
*
...
...
@@ -103,9 +109,21 @@ static void zeroes(FAR struct lib_outstream_s *obj, int nzeroes)
}
/****************************************************************************
* Private Functions
* Name: lib_dtoa_string
*
* Description:
* Print the specified string
*
****************************************************************************/
static
void
lib_dtoa_string
(
FAR
struct
lib_outstream_s
*
obj
,
const
char
*
str
)
{
while
(
*
str
)
{
obj
->
put
(
obj
,
*
str
++
);
}
}
/****************************************************************************
* Name: lib_dtoa
*
...
...
@@ -140,6 +158,25 @@ static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec,
int
dsgn
;
/* Unused sign indicator */
int
i
;
/* Special handling for NaN and Infinity */
if
(
isnan
(
value
))
{
lib_dtoa_string
(
obj
,
"NaN"
);
return
;
}
if
(
isinf
(
value
))
{
if
(
value
<
0
.
0
d
)
{
obj
->
put
(
obj
,
'-'
);
}
lib_dtoa_string
(
obj
,
"Infinity"
);
return
;
}
/* Non-zero... positive or negative */
if
(
value
<
0
)
...
...
@@ -173,7 +210,7 @@ static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec,
obj
->
put
(
obj
,
'0'
);
/* A decimal point is printed only in the alternate form or if a
/* A decimal point is printed only in the alternate form or if a
* particular precision is requested.
*/
...
...
@@ -227,7 +264,7 @@ static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec,
for
(
i
=
expt
;
i
>
0
;
i
--
)
{
if
(
*
digits
!=
'\0'
)
{
{
obj
->
put
(
obj
,
*
digits
);
digits
++
;
}
...
...
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