Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
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
Container registry
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
dc948e4d
Commit
dc948e4d
authored
7 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py/formatfloat: Use standard isinf, isnan funcs instead of custom ones.
Reduces code size by a tiny bit.
parent
08a19669
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
py/formatfloat.c
+4
-7
4 additions, 7 deletions
py/formatfloat.c
with
4 additions
and
7 deletions
py/formatfloat.c
+
4
−
7
View file @
dc948e4d
...
...
@@ -69,12 +69,10 @@ union floatbits {
uint32_t
u
;
};
static
inline
int
fp_signbit
(
float
x
)
{
union
floatbits
fb
=
{
x
};
return
fb
.
u
&
FLT_SIGN_MASK
;
}
static
inline
in
t
fp_is
special
(
float
x
)
{
union
floatbits
fb
=
{
x
};
return
(
fb
.
u
&
FLT_EXP_MASK
)
==
FLT_EXP_MASK
;
}
static
inline
in
t
fp_isinf
(
float
x
)
{
union
floatbits
fb
=
{
x
};
return
(
fb
.
u
&
FLT_MAN_MASK
)
==
0
;
}
#def
in
e
fp_is
nan(x) isnan(x)
#def
in
e
fp_isinf(
x) isinf(x)
static
inline
int
fp_iszero
(
float
x
)
{
union
floatbits
fb
=
{
x
};
return
fb
.
u
==
0
;
}
static
inline
int
fp_isless1
(
float
x
)
{
union
floatbits
fb
=
{
x
};
return
fb
.
u
<
0x3f800000
;
}
// Assumes both fp_isspecial() and fp_isinf() were applied before
#define fp_isnan(x) 1
#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
...
...
@@ -84,7 +82,6 @@ static inline int fp_isless1(float x) { union floatbits fb = {x}; return fb.u <
#define FPDECEXP 256
#define FPMIN_BUF_SIZE 7 // +9e+199
#define fp_signbit(x) signbit(x)
#define fp_isspecial(x) 1
#define fp_isnan(x) isnan(x)
#define fp_isinf(x) isinf(x)
#define fp_iszero(x) (x == 0)
...
...
@@ -122,7 +119,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
}
return
buf_size
>=
2
;
}
if
(
fp_signbit
(
f
)
&&
!
isnan
(
f
))
{
if
(
fp_signbit
(
f
)
&&
!
fp_
isnan
(
f
))
{
*
s
++
=
'-'
;
f
=
-
f
;
}
else
{
...
...
@@ -135,7 +132,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
// It is buf_size minus room for the sign and null byte.
int
buf_remaining
=
buf_size
-
1
-
(
s
-
buf
);
if
(
fp_isspecial
(
f
))
{
{
char
uc
=
fmt
&
0x20
;
if
(
fp_isinf
(
f
))
{
*
s
++
=
'I'
^
uc
;
...
...
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