예제 #1
0
def setContextForRoundingMode(smtRoundingMode):
    if smtRoundingMode == "rnd-to-zero":
        bigfloat.setcontext(bigfloat.RoundTowardZero)
        decimal.getcontext().rounding = ROUND_DOWN  #(towards zero),
    elif smtRoundingMode == "rnd-to-positive":
        bigfloat.setcontext(bigfloat.RoundTowardPositive)
        decimal.getcontext().rounding = ROUND_CEILING  #(towards Infinity)
    elif smtRoundingMode == "rnd-to-negative":
        bigfloat.setcontext(bigfloat.RoundTowardNegative)
        decimal.getcontext().rounding = ROUND_FLOOR  #(towards -Infinity),
    elif smtRoundingMode == "rnd-to-nearest-away":
        bigfloat.setcontext(bigfloat.RoundAwayFromZero)
        decimal.getcontext(
        ).rounding = ROUND_HALF_UP  #(to nearest with ties going away from zero)
    elif smtRoundingMode == "rnd-to-nearest-even":
        bigfloat.setcontext(bigfloat.RoundTiesToEven)
        decimal.getcontext(
        ).rounding = ROUND_HALF_EVEN  #(to nearest with ties going to nearest even integer)
예제 #2
0
        return d

def MultiBuddhabrot(numprocs, secs, its, width, height, rect=draw.FloatRect(2)):
    manager = multiprocessing.Manager()
    rlist = manager.list()
    def fn(rlist):
        print "start"
        bud = Buddhabrot(secs, its, width, height, rect)
        bud.populate()
        rlist.append(bud)
    procs = [multiprocessing.Process(target=fn,args=(rlist,)) for i in xrange(numprocs)]
    [p.start() for p in procs]
    [p.join() for p in procs]
    result = Buddhabrot(secs, its, width, height, rect)
    for bud in rlist:
        result.data += bud.data
    return result
        

if __name__ == '__main__':
    bigfloat.setcontext(bigfloat.precision(52))
    #man = Mandlebrot(100)
    #d = draw.Draw(1024, 1024, draw.FloatRect(2.0))
#    bud = MultiBuddhabrot(8, 10, [20,200,2000], 1024, 1024)
#    bud.pickle("man.pck")
    bud = cPickle.load(open("man.pck", "rb"))
    bud.unpickle("man.npy")
    d = bud.draw()
    d.save("/vagrant/man.png")
    
예제 #3
0
 def setUp(self):
     setcontext(DefaultTestContext)
예제 #4
0
 def setUp(self):
     setcontext(DefaultTestContext)
예제 #5
0
#     1/8	= 	0.125
#     1/9	= 	0.(1)
#     1/10	= 	0.1
#
# Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring
# cycle.
#
# Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.

from bigfloat import getcontext, setcontext, BigFloat, precision

largest_cycle_denominator = 0
largest_cycle_length = 0

default_context = getcontext()
setcontext(precision(10000))
for i in range(1, 1000):
    big_decimal = str(1 / BigFloat(i))
    right_substring_limit = 3
    while big_decimal[2:right_substring_limit] in big_decimal[
            right_substring_limit:]:
        right_substring_limit += 1
        substring = big_decimal[2:right_substring_limit]
        next_potential_cycle = big_decimal[
            right_substring_limit:right_substring_limit + len(substring)]
        if substring == next_potential_cycle:
            break

    cycle = big_decimal[2:right_substring_limit]
    print('1/{}: {}'.format(i, cycle))
    if len(cycle) > largest_cycle_length:
예제 #6
0
from bigfloat import precision, setcontext, BigFloat

setcontext(precision(500))

f = BigFloat(0.1)
print f
for i in xrange(10000):
    f /= 2
print f
예제 #7
0
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ParaTAXIS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ParaTAXIS.  If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import bigfloat as bf
from bigfloat import BigFloat
bf.setcontext(bf.precision(128))


class SimulationData:
    """Holds data about the simulation
    
       size in pixels
       cellSize: Size per cell in meters
    """
    def __init__(self, size, cellSize):
        self.size = np.array(size)
        self.cellSize = np.array(cellSize).astype(BigFloat)

    def __str__(self):
        return "Size: " + str(self.size) + ", cellSize: " + str(self.cellSize)
예제 #8
0
    print("IntMDCT:")
    y0, y1 = IntMDCTanafb(x, N, fb)  #compute the IntMDCT of the stereo signal
    ychan = np.stack(
        (y0, y1),
        axis=0)  #combine spectra into a 3-d array, 1st dim is channel
    print("y0.shape=", y0.shape)
    numblocks = y0.shape[1]
    #write number of samples in byte stream:
    numbl = struct.pack('I', np.uint32(numblocks))  #'I' for unsigned integer
    codedfile.write(numbl)
    bytearray = []
    #bytearray=np.ubyte(np.append(bytearray,strlen%(2**8))) #LSB
    #bytearray=np.ubyte(np.append(bytearray, strlen*(2**(-8)))) #MSB
    print("numblocks=", numblocks)
    bigfloat.setcontext(bigfloat.precision(30 * numblocks))
    print("BigFloat precision:", 30 * numblocks)
    for chan in range(channels):  #loop over channels:
        print("channel ", chan)
        print("Arithmetic Coding:")
        for k in range(N):  #loop across subbands:
            #if (k%100==0):
            print("Subband:", k)

            origintarray = ychan[chan, k, :].astype(np.int32)
            print("max(np.abs(origintarray))", max(np.abs(origintarray)))
            encoded, prec, sigma, strlen = encode(origintarray)
            #print("strlen=", strlen)
            print("prec=", prec, "sigma=", sigma)
            #convert bigfloat to bytes in encoder:
            encblock = encoded
예제 #9
0
 def tearDown(self):
     setcontext(self._original_context)
     del self._original_context
예제 #10
0
 def setUp(self):
     self._original_context = getcontext()
     setcontext(DefaultTestContext)