Exemplo n.º 1
0
 def test_acceleration_moving(self, motor : Motor) :
     for microstep_resolution in Motor.MICROSTEP_RESOLUTIONS :
         motor.microstep_resolution = microstep_resolution
         velocity_minimum = motor.velocity_minimum
         velocity_maximum = motor.velocity_maximum
         velocity_range = velocity_maximum - velocity_minimum
         for velocity_portion in range(1, 11) :
             velocity = velocity_minimum + velocity_range * velocity_portion / 10
             motor.velocity_moving = velocity
             acceleration_minimum = motor.acceleration_minimum
             acceleration_maximum = motor.acceleration_maximum
             with self.assertRaises(ValueError) :
                 motor.acceleration_moving = math.nextafter(acceleration_minimum, -math.inf)
             with self.assertRaises(ValueError) :
                 motor.acceleration_moving = math.nextafter(acceleration_maximum, +math.inf)
             motor.acceleration_moving = acceleration_minimum
             self.assertEqual(motor.acceleration_moving, acceleration_minimum)
             motor.acceleration_moving = acceleration_maximum
             self.assertEqual(motor.acceleration_moving, acceleration_maximum)
             acceleration_range = acceleration_maximum - acceleration_minimum
             for portion in range(1, 100) :
                 acceleration = acceleration_minimum + acceleration_range * portion / 100
                 motor.acceleration_moving = acceleration
                 error_absolute = motor.acceleration_moving - acceleration
                 error_relative = error_absolute / acceleration
                 self.assertLessEqual(error_relative, 0.0)
                 self.assertGreater(error_relative, -0.025)
Exemplo n.º 2
0
 def test_velocity_moving(self, motor : Motor) :
     for microstep_resolution in Motor.MICROSTEP_RESOLUTIONS :
         motor.microstep_resolution = microstep_resolution
         velocity_minimum = motor.velocity_minimum
         velocity_maximum = motor.velocity_maximum
         with self.assertRaises(ValueError) :
             motor.velocity_moving = math.nextafter(velocity_minimum, -math.inf)
         with self.assertRaises(ValueError) :
             motor.velocity_moving = math.nextafter(velocity_maximum, +math.inf)
         motor.velocity_moving = velocity_minimum
         self.assertEqual(motor.velocity_moving, velocity_minimum)
         motor.velocity_moving = velocity_maximum
         self.assertEqual(motor.velocity_moving, velocity_maximum)
         velocity_range = velocity_maximum - velocity_minimum
         for portion in range(1, 100) :
             velocity = velocity_minimum + velocity_range * portion / 100
             motor.velocity_moving = velocity
             error_absolute = motor.velocity_moving - velocity
             error_relative = error_absolute / velocity
             self.assertLessEqual(error_relative, 0.0)
             self.assertGreater(error_relative, -0.001)
import math

pow(3, 2)
for i in range(1, 11):
    print(pow(i, 2))  # for print the square of first 10 numbers
    print(pow(i, 3))  # for print the cube of first 10 numbers
    print(pow(i, 0.5))  # for print the square root of first 10 numbers

lst = [11, 32, 34, 54, 67, 87, 24, 55, 36, 87]
max(lst)  # returns the maximum numbers
min(lst)  # returns the minimum numbers
math.ceil(5)  # ceil and floor numbers
math.copysign(5, -1)  # copy the sign of y
math.factorial(5)  # returns the factorial of the numbers
math.fmod(40, 6)  # returns the remainder
math.frexp(5)  # returns the exponent of x as the pair of (m,e)
math.sum(lst)  # returns the sum of the values present
math.exp(5)  # returns the exponent of (e,5)
math.expm1(6)  # returns the value of e**x-1
math.sqrt(5)  # returns the square root of x
math.gcd(46, 84)  # returns the greatest common divisor
math.lcm(25, 20)  # returns the least common multiple
math.nextafter(
    34, 36
)  # returns the next number in floting point either towards zero/opposite
math.prod(lst)  # returns the product of all availale iterables
math.remainder(6, 5)  # returns the reaminder
Exemplo n.º 4
0
import math

# Greatest common divisor
print(math.gcd(80, 64, 152))

# Least common multiple
print(math.lcm(4, 8, 5))

# Next float after 4 going towards 5
# 4.000000000000001
print(math.nextafter(4, 5))

# Next float after 9 going towards 0
# 8.999999999999998
print(math.nextafter(9, 0))

# Unit in the Last Place
# 0.125
print(math.ulp(1000000000000000))

# 4.440892098500626e-16
print(math.ulp(3.14159265))
def shrink(n, fnum):
    ret = fnum
    for x in range(n):
        ret = math.nextafter(ret, -math.inf)
    return ret
Exemplo n.º 6
0
import math

print(math.nextafter(1.0,math.inf) - 1.0)
Exemplo n.º 7
0
assert math.gcd(1, -1) == 1
assert math.gcd(-1, -1) == 1
assert math.gcd(125, -255) == 5
assert_raises(TypeError, lambda: math.gcd(1.1, 2))

assert math.factorial(0) == 1
assert math.factorial(1) == 1
assert math.factorial(2) == 2
assert math.factorial(3) == 6
assert math.factorial(10) == 3628800
assert math.factorial(20) == 2432902008176640000
assert_raises(ValueError, lambda: math.factorial(-1))

if hasattr(math, 'nextafter'):
    try:
        assert math.nextafter(4503599627370496.0, -INF) == 4503599627370495.5
        assert math.nextafter(4503599627370496.0, INF) == 4503599627370497.0
        assert math.nextafter(9223372036854775808.0,
                              0.0) == 9223372036854774784.0
        assert math.nextafter(-9223372036854775808.0,
                              0.0) == -9223372036854774784.0
        assert math.nextafter(4503599627370496, -INF) == 4503599627370495.5
        assert math.nextafter(2.0, 2.0) == 2.0
        assert math.isnan(math.nextafter(NAN, 1.0))
    except NotImplementedError:
        # WASM
        pass

assert math.modf(1.25) == (0.25, 1.0)
assert math.modf(-1.25) == (-0.25, -1.0)
assert math.modf(2.56) == (0.56, 2.0)