Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Hey let's not be a quitter

    >>> (Decimal(5000).exp() * Decimal(6000).exp()).ln()
    Decimal('11000.00000000000000000000000')


Nice catch, but then:

    In [13]: Decimal(5000000).exp() * Decimal(5000000).exp()
    ---------------------------------------------------------------------------
    Overflow                                  Traceback (most recent call last)
    <ipython-input-13-8333724ae893> in <module>()
    ----> 1 Decimal(5000000).exp() * Decimal(5000000).exp()

    Overflow: [<class 'decimal.Overflow'>]
The problem is that the multiplication blows the precision of the used format (either double for math.log(...) or the one the decimal module uses).

I had also thought about the intention of the question trying to get you to express the sum as bit operations (thought I admit that sounds like going for a very low-level profile), or maybe just "thinking outside the box".


Hey don't be a quitter, we can make Decimal support way bigger numbers via context


Alternative, buzzwordy approach: let's train a convolutional neural network to do addition!


Can it run the MEAN stack?


Yes, and we'll deploy it on The Cloud.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: