[Python] How to serialize mpf object to raw binary bytes or bytearray in python mpmath

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a python program that uses mpmath to implement the Chunovsky algorithm for computing pi. I want to make my program log its progress to a file on regular intervals, so that I can recover progress if there's a power outage or something similar, since the program will be running for a while. I'm using a dps of about a million, so converting to a decimal string is very slow. I need a way to encode an mpf object as a raw binary bytes or bytearray object. I can't seem to find anything about this in the mpmath documentation. I could serialize it with pickle, but I think it would be slower than necessary, since it would serialize more information than I need.

    Continue reading...

Compartilhe esta Página