<s> from mpmath . libmp import * <EOL> from mpmath import mpf , mp <EOL> from random import randint , choice , seed <EOL> all_modes = [ round_floor , round_ceiling , round_down , round_up , round_nearest ] <EOL> fb = from_bstr <EOL> fi = from_int <EOL> ff = from_float <EOL> def test_div_1_3 ( ) : <EOL> a = fi ( <NUM_LIT:1> ) <EOL> b = fi ( <NUM_LIT:3> ) <EOL> c = fi ( - <NUM_LIT:1> ) <EOL> assert mpf_div ( a , b , <NUM_LIT:7> , round_floor ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( a , b , <NUM_LIT:7> , round_ceiling ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( a , b , <NUM_LIT:7> , round_down ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( a , b , <NUM_LIT:7> , round_up ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( a , b , <NUM_LIT:7> , round_nearest ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:7> , round_floor ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:7> , round_ceiling ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:7> , round_down ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:7> , round_up ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:7> , round_nearest ) == fb ( '<STR_LIT>' ) <EOL> def test_mpf_divi_1_3 ( ) : <EOL> a = <NUM_LIT:1> <EOL> b = fi ( <NUM_LIT:3> ) <EOL> c = - <NUM_LIT:1> <EOL> assert mpf_rdiv_int ( a , b , <NUM_LIT:7> , round_floor ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_rdiv_int ( a , b , <NUM_LIT:7> , round_ceiling ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_rdiv_int ( a , b , <NUM_LIT:7> , round_down ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_rdiv_int ( a , b , <NUM_LIT:7> , round_up ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_rdiv_int ( a , b , <NUM_LIT:7> , round_nearest ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_rdiv_int ( c , b , <NUM_LIT:7> , round_floor ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_rdiv_int ( c , b , <NUM_LIT:7> , round_ceiling ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_rdiv_int ( c , b , <NUM_LIT:7> , round_down ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_rdiv_int ( c , b , <NUM_LIT:7> , round_up ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_rdiv_int ( c , b , <NUM_LIT:7> , round_nearest ) == fb ( '<STR_LIT>' ) <EOL> def test_div_300 ( ) : <EOL> q = fi ( <NUM_LIT> ) <EOL> a = fi ( <NUM_LIT> ) <EOL> b = fi ( <NUM_LIT> ) <EOL> c = fi ( <NUM_LIT> ) <EOL> assert mpf_div ( a , q , <NUM_LIT:9> , round_down ) == fi ( <NUM_LIT> ) <EOL> assert mpf_div ( b , q , <NUM_LIT:9> , round_down ) == fi ( <NUM_LIT> ) <EOL> assert mpf_div ( c , q , <NUM_LIT:9> , round_down ) == fi ( <NUM_LIT> ) <EOL> assert mpf_div ( a , q , <NUM_LIT:9> , round_up ) == fi ( <NUM_LIT> ) <EOL> assert mpf_div ( b , q , <NUM_LIT:9> , round_up ) == fi ( <NUM_LIT> ) <EOL> assert mpf_div ( c , q , <NUM_LIT:9> , round_up ) == fi ( <NUM_LIT> ) <EOL> assert mpf_div ( a , q , <NUM_LIT:9> , round_nearest ) == fi ( <NUM_LIT> ) <EOL> assert mpf_div ( b , q , <NUM_LIT:9> , round_nearest ) == fi ( <NUM_LIT> ) <EOL> assert mpf_div ( c , q , <NUM_LIT:9> , round_nearest ) == fi ( <NUM_LIT> ) <EOL> a = fi ( <NUM_LIT> ) <EOL> b = fi ( <NUM_LIT> ) <EOL> c = fi ( <NUM_LIT> ) <EOL> assert mpf_div ( a , q , <NUM_LIT:9> , round_nearest ) == fi ( <NUM_LIT> ) <EOL> assert mpf_div ( b , q , <NUM_LIT:9> , round_nearest ) == fi ( <NUM_LIT> ) <EOL> assert mpf_div ( c , q , <NUM_LIT:9> , round_nearest ) == fi ( <NUM_LIT> ) <EOL> def test_tight_integer_division ( ) : <EOL> N = <NUM_LIT:100> <EOL> seed ( <NUM_LIT:1> ) <EOL> for i in range ( N ) : <EOL> a = choice ( [ <NUM_LIT:1> , - <NUM_LIT:1> ] ) * randint ( <NUM_LIT:1> , <NUM_LIT:1> << randint ( <NUM_LIT:10> , <NUM_LIT:100> ) ) <EOL> b = choice ( [ <NUM_LIT:1> , - <NUM_LIT:1> ] ) * randint ( <NUM_LIT:1> , <NUM_LIT:1> << randint ( <NUM_LIT:10> , <NUM_LIT:100> ) ) <EOL> p = a * b <EOL> width = bitcount ( abs ( b ) ) - trailing ( b ) <EOL> a = fi ( a ) ; b = fi ( b ) ; p = fi ( p ) <EOL> for mode in all_modes : <EOL> assert mpf_div ( p , a , width , mode ) == b <EOL> def test_epsilon_rounding ( ) : <EOL> a = fb ( '<STR_LIT>' + ( '<STR_LIT:0>' * <NUM_LIT:200> ) + '<STR_LIT:1>' ) <EOL> b = fb ( '<STR_LIT>' ) <EOL> c = mpf_mul ( a , b , <NUM_LIT> , round_floor ) <EOL> assert mpf_div ( c , b , bitcount ( a [ <NUM_LIT:1> ] ) , round_floor ) == a <EOL> assert mpf_div ( c , b , <NUM_LIT:2> , round_down ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:3> , round_down ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:2> , round_up ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:3> , round_up ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:2> , round_floor ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:3> , round_floor ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:2> , round_ceiling ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:3> , round_ceiling ) == fb ( '<STR_LIT>' ) <EOL> a = fb ( '<STR_LIT>' + ( '<STR_LIT:0>' * <NUM_LIT:200> ) + '<STR_LIT:1>' ) <EOL> b = fb ( '<STR_LIT>' ) <EOL> c = mpf_mul ( a , b , <NUM_LIT> , round_floor ) <EOL> assert mpf_div ( c , b , bitcount ( a [ <NUM_LIT:1> ] ) , round_floor ) == a <EOL> assert mpf_div ( c , b , <NUM_LIT:2> , round_down ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:3> , round_up ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:2> , round_floor ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:3> , round_floor ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:2> , round_ceiling ) == fb ( '<STR_LIT>' ) <EOL> assert mpf_div ( c , b , <NUM_LIT:3> , round_ceiling ) == fb ( '<STR_LIT>' ) <EOL> def test_mod ( ) : <EOL> mp . dps = <NUM_LIT:15> <EOL> assert mpf ( <NUM_LIT> ) % <NUM_LIT:1> == <NUM_LIT:0> <EOL> assert mpf ( - <NUM_LIT:3> ) % <NUM_LIT> == <NUM_LIT> <EOL> assert mpf ( <NUM_LIT> ) % <NUM_LIT> == <NUM_LIT> <EOL> assert mpf ( <NUM_LIT> ) % - <NUM_LIT> == - <NUM_LIT> <EOL> assert mpf ( - <NUM_LIT> ) % <NUM_LIT> == <NUM_LIT> <EOL> assert mpf ( - <NUM_LIT> ) % - <NUM_LIT> == - <NUM_LIT> <EOL> assert mpf ( '<STR_LIT>' ) % <NUM_LIT:1> == <NUM_LIT:0> <EOL> assert mpf ( '<STR_LIT>' ) % <NUM_LIT:1> == mpf ( '<STR_LIT>' ) <EOL> assert <NUM_LIT:3> % mpf ( '<STR_LIT>' ) == <NUM_LIT> <EOL> def test_div_negative_rnd_bug ( ) : <EOL> mp . dps = <NUM_LIT:15> <EOL> assert ( - <NUM_LIT:3> ) / mpf ( '<STR_LIT>' ) == mpf ( '<STR_LIT>' ) <EOL> assert mpf ( '<STR_LIT>' ) / mpf ( '<STR_LIT>' ) == mpf ( '<STR_LIT>' ) </s>
