...
 
Commits (8)
......@@ -28,10 +28,11 @@
#include <string.h>
#include "py/runtime.h"
#include "extmod/machine_spi.h"
#if MICROPY_PY_MACHINE_SPI
#include "extmod/machine_spi.h"
// if a port didn't define MSB/LSB constants then provide them
#ifndef MICROPY_PY_MACHINE_SPI_MSB
#define MICROPY_PY_MACHINE_SPI_MSB (0)
......
......@@ -309,6 +309,8 @@ mp_raw_code_t *mp_raw_code_load_file(const char *filename) {
}
#if defined(MICROPY_SPARC_NUM_REG_WINDOWS)
#include <rtems.h> // for sparc_disable_interrupts, sparc_enable_interrupts
// This is called by the memory manager when a garbage collection is needed.
void gc_collect(void) {
gc_collect_start();
......
inf
inf
0.0
0.0
0.0
1.0
1.0
inf
inf
# check special cases of pow that shouldn't raise
import math
# these cases would originally raise ValueError
print(math.pow(0.9, -float('inf')))
print(math.pow(-0.9, -float('inf')))
print(math.pow(0.9, float('inf')))
print(math.pow(-0.9, float('inf')))
print(math.pow(0.0, float('inf')))
print(math.pow(1.0, 0.0))
print(math.pow(-1.0, 0.0))
print(math.pow(1.1, float('inf')))
print(math.pow(-1.1, float('inf')))
1.000000e-300
1.000000e-315
1.400000e-315
1.000000e+300
0.000000e+00
0.000000e+00
# round would overflow internally with large second arg
print('%e' % round(1.4e-300, 300))
print('%e' % round(1.4e-315, 315))
print('%e' % round(1.4e-315, 400))
print('%e' % round(1.4e+300, -300))
print('%e' % round(1.4e+305, -320))
print('%e' % round(1.4e+305, -330))
......@@ -473,9 +473,15 @@ STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) {
mp_float_t val = mp_obj_get_float(o_in);
if (n_args > 1) {
mp_int_t num_dig = mp_obj_get_int(args[1]);
mp_float_t mult = MICROPY_FLOAT_C_FUN(pow)(10, num_dig);
mp_float_t val_mult = val * mult;
if (!isfinite(val_mult)) {
mp_float_t mult0 = 1;
if (num_dig > 30) {
// Split up the power so it doesn't overflow (single or double prec)
mult0 = 1e30;
num_dig -= 30;
}
mp_float_t mult1 = MICROPY_FLOAT_C_FUN(pow)(10, num_dig);
mp_float_t val_mult = val * mult0 * mult1;
if (!isfinite(val_mult) || mult1 == 0) {
if (num_dig >= 0) {
// Overflow in number of digits so just keep them all and return original number
return o_in;
......@@ -484,7 +490,7 @@ STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) {
return mp_obj_new_float(0 * val);
}
}
mp_float_t rounded = MICROPY_FLOAT_C_FUN(nearbyint)(val_mult) / mult;
mp_float_t rounded = MICROPY_FLOAT_C_FUN(nearbyint)(val_mult) / mult0 / mult1;
if (!isfinite(rounded)) {
mp_raise_msg(&mp_type_OverflowError, NULL);
}
......
......@@ -112,7 +112,16 @@ mp_float_t MICROPY_FLOAT_C_FUN(log2)(mp_float_t x) {
// sqrt(x): returns the square root of x
MATH_FUN_1(sqrt, sqrt)
// pow(x, y): returns x to the power of y
MATH_FUN_2(pow, pow)
STATIC mp_obj_t mp_math_pow(mp_obj_t x_obj, mp_obj_t y_obj) {
mp_float_t x = mp_obj_get_float(x_obj);
mp_float_t y = mp_obj_get_float(y_obj);
mp_float_t ans = pow(x, y);
if ((isnan(ans) && !isnan(x) && !isnan(y)) || (isinf(ans) && !isinf(x) && !isinf(y))) {
math_error();
}
return mp_obj_new_float(ans);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_pow_obj, mp_math_pow);
// exp(x)
MATH_FUN_1(exp, exp)
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
......
......@@ -169,12 +169,12 @@ static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o)
#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
static inline bool MP_OBJ_IS_SMALL_INT(mp_const_obj_t o)
{ return ((((mp_int_t)(o)) & 0xffff000000000000) == 0x0001000000000000); }
{ return ((((mp_int_t)(o)) & 0xffff000000000000ULL) == 0x0001000000000000ULL); }
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)((o) << 16)) >> 17)
#define MP_OBJ_NEW_SMALL_INT(small_int) (((((uint64_t)(small_int)) & 0x7fffffffffff) << 1) | 0x0001000000000001)
static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
{ return ((((mp_int_t)(o)) & 0xffff000000000000) == 0x0002000000000000); }
{ return ((((mp_int_t)(o)) & 0xffff000000000000ULL) == 0x0002000000000000ULL); }
#define MP_OBJ_QSTR_VALUE(o) ((((uint32_t)(o)) >> 1) & 0xffffffff)
#define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 1) | 0x0002000000000001))
......@@ -183,13 +183,13 @@ static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
#define mp_const_float_pi {((mp_obj_t)((uint64_t)0x400921fb54442d18 + 0x8004000000000000))}
static inline bool mp_obj_is_float(mp_const_obj_t o) {
return ((uint64_t)(o) & 0xfffc000000000000) != 0;
return ((uint64_t)(o) & 0xfffc000000000000ULL) != 0;
}
static inline mp_float_t mp_obj_float_get(mp_const_obj_t o) {
union {
mp_float_t f;
uint64_t r;
} num = {.r = o - 0x8004000000000000};
} num = {.r = o - 0x8004000000000000ULL};
return num.f;
}
static inline mp_obj_t mp_obj_new_float(mp_float_t f) {
......@@ -197,12 +197,12 @@ static inline mp_obj_t mp_obj_new_float(mp_float_t f) {
mp_float_t f;
uint64_t r;
} num = {.f = f};
return num.r + 0x8004000000000000;
return num.r + 0x8004000000000000ULL;
}
#endif
static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o)
{ return ((((uint64_t)(o)) & 0xffff000000000000) == 0x0000000000000000); }
{ return ((((uint64_t)(o)) & 0xffff000000000000ULL) == 0x0000000000000000); }
#define MP_OBJ_TO_PTR(o) ((void*)(uintptr_t)(o))
#define MP_OBJ_FROM_PTR(p) ((mp_obj_t)((uintptr_t)(p)))
......
......@@ -248,7 +248,6 @@ PY_EXTMOD_O_BASENAME = \
extmod/vfs_fat_file.o \
extmod/utime_mphal.o \
extmod/uos_dupterm.o \
lib/embed/abort_.o \
lib/utils/printf.o \
# prepend the build destination prefix to the py object files
......