Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
c585ad10
Commit
c585ad10
authored
Jan 13, 2015
by
David Steinberg
Committed by
Damien George
Jan 24, 2015
Browse files
py: Move mp_float_t related defines to misc.h
parent
6b636738
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/misc.h
View file @
c585ad10
...
...
@@ -183,4 +183,17 @@ static inline mp_uint_t count_lead_ones(byte val) {
}
#endif
/** float internals *************/
#if MICROPY_PY_BUILTINS_FLOAT
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
#define MP_FLOAT_EXP_BITS (11)
#define MP_FLOAT_FRAC_BITS (52)
#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
#define MP_FLOAT_EXP_BITS (8)
#define MP_FLOAT_FRAC_BITS (23)
#endif
#define MP_FLOAT_EXP_BIAS ((1 << (MP_FLOAT_EXP_BITS - 1)) - 1)
#endif // MICROPY_PY_BUILTINS_FLOAT
#endif // __MICROPY_INCLUDED_PY_MISC_H__
py/mpz.c
View file @
c585ad10
...
...
@@ -698,29 +698,25 @@ void mpz_set_from_ll(mpz_t *z, long long val, bool is_signed) {
#if MICROPY_PY_BUILTINS_FLOAT
void
mpz_set_from_float
(
mpz_t
*
z
,
mp_float_t
src
)
{
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
#define EXP_SZ 11
#define FRC_SZ 52
typedef
uint64_t
mp_float_int_t
;
#else
#define EXP_SZ 8
#define FRC_SZ 23
#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
typedef
uint32_t
mp_float_int_t
;
#endif
union
{
mp_float_t
f
;
struct
{
mp_float_int_t
frc
:
FRC_S
Z
,
exp
:
EXP_SZ
,
sgn
:
1
;
}
p
;
struct
{
mp_float_int_t
frc
:
MP_FLOAT_
FR
A
C_
BIT
S
,
exp
:
MP_FLOAT_EXP_BITS
,
sgn
:
1
;
}
p
;
}
u
=
{
src
};
z
->
neg
=
u
.
p
.
sgn
;
if
(
u
.
p
.
exp
==
0
)
{
// value == 0 || value < 1
mpz_set_from_int
(
z
,
0
);
}
else
if
(
u
.
p
.
exp
==
((
1
<<
EXP_SZ
)
-
1
))
{
}
else
if
(
u
.
p
.
exp
==
((
1
<<
MP_FLOAT_EXP_BITS
)
-
1
))
{
// u.p.frc == 0 indicates inf, else NaN
// should be handled by caller
mpz_set_from_int
(
z
,
0
);
}
else
{
const
int
adj_exp
=
(
int
)
u
.
p
.
exp
-
((
1
<<
(
EXP_SZ
-
1
))
-
1
)
;
const
int
adj_exp
=
(
int
)
u
.
p
.
exp
-
MP_FLOAT_EXP_BIAS
;
if
(
adj_exp
<
0
)
{
// value < 1 , truncates to 0
mpz_set_from_int
(
z
,
0
);
...
...
@@ -732,15 +728,15 @@ typedef uint32_t mp_float_int_t;
const
int
dig_cnt
=
(
adj_exp
+
1
+
(
DIG_SIZE
-
1
))
/
DIG_SIZE
;
const
unsigned
int
rem
=
adj_exp
%
DIG_SIZE
;
int
dig_ind
,
shft
;
mp_float_int_t
frc
=
u
.
p
.
frc
|
((
mp_float_int_t
)
1
<<
FRC_S
Z
);
mp_float_int_t
frc
=
u
.
p
.
frc
|
((
mp_float_int_t
)
1
<<
MP_FLOAT_
FR
A
C_
BIT
S
);
if
(
adj_exp
<
FRC_S
Z
)
{
if
(
adj_exp
<
MP_FLOAT_
FR
A
C_
BIT
S
)
{
shft
=
0
;
dig_ind
=
0
;
frc
>>=
FRC_S
Z
-
adj_exp
;
frc
>>=
MP_FLOAT_
FR
A
C_
BIT
S
-
adj_exp
;
}
else
{
shft
=
(
rem
-
FRC_S
Z
)
%
DIG_SIZE
;
dig_ind
=
(
adj_exp
-
FRC_S
Z
)
/
DIG_SIZE
;
shft
=
(
rem
-
MP_FLOAT_
FR
A
C_
BIT
S
)
%
DIG_SIZE
;
dig_ind
=
(
adj_exp
-
MP_FLOAT_
FR
A
C_
BIT
S
)
/
DIG_SIZE
;
}
mpz_need_dig
(
z
,
dig_cnt
);
z
->
len
=
dig_cnt
;
...
...
@@ -758,8 +754,6 @@ typedef uint32_t mp_float_int_t;
}
}
}
#undef EXP_SZ
#undef FRC_SZ
#endif
// returns number of bytes from str that were processed
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment