WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Rust on piCore: Computing π to 10,000 digits  (Read 448 times)

Offline geev03

  • Wiki Author
  • Newbie
  • *****
  • Posts: 43
Rust on piCore: Computing π to 10,000 digits
« on: January 23, 2026, 07:38:53 AM »

Got Rust working on **piCore (Raspberry Pi 400)** and successfully compiled a Chudnovsky‑based π calculator using the `rug` big‑number crate.

**Steps:**
- Install Rust and toolchain: 
  ```
Code: [Select]
  tce-load -wi rust compiletc binutils make  ```
- Create project: 
  ```
Code: [Select]
  cargo new pi_calc  ```
- Add to `Cargo.toml`: 
  ```toml
  [dependencies]
  rug = "1.28"
  ```

**Simple Chudnovsky implementation (works on piCore):**

Code: [Select]
```rust
use rug::{Float};
use rug::ops::Pow;

fn main() {
    let digits: u32 = 10000;
    let prec: u32 = digits + 20;

    let pi = compute_pi(prec);
    println!("{}", pi.to_string_radix(10, Some((digits + 2) as usize)));
}

fn compute_pi(prec: u32) -> Float {
    let mut sum = Float::with_val(prec, 0);
    for k in 0..20 {
        let f6k = factorial(6 * k);
        let f3k = factorial(3 * k);
        let fk  = factorial(k);

        let a = Float::with_val(prec, 13591409 + 545140134 * k as i32);
        let b = Float::with_val(prec, 640320).pow(3 * k + 1);

        let term = Float::with_val(prec, &f6k * a / (&f3k * fk.pow(3) * b));
        if k % 2 == 0 { sum += term } else { sum -= term }
    }
    Float::with_val(prec, 1) / (Float::with_val(prec, 12) * sum)
}

fn factorial(n: u32) -> Float {
    let mut f = Float::with_val(128, 1);
    for i in 2..=n { f *= i }
    f
}
```

Outputs π to 10k digits on a Pi 400 without issues. 

    [Edit]: Added code tags.  Rich
« Last Edit: January 23, 2026, 08:15:01 AM by Rich »

Offline geev03

  • Wiki Author
  • Newbie
  • *****
  • Posts: 43
Re: Rust on piCore: Computing π to 10,000 digits
« Reply #1 on: January 23, 2026, 07:55:54 AM »
Code: [Select]
root@box:/home/tc/bin# ./sysinfo

            .~~.   .~~.
           '. \ ' ' / .'
        .~~ .~~~..~~~. ~~.
       : .~.'~'.~~.'~'.~. :
      ~ (   ) (  @  ) (   ) ~
     ( : '~'.~.'~~'.~.'~' : )
      ~ .~ (   ) ~~ (   ) ~
       (  : '~' :~~: '~' :  )
        '~ .~~~. ~  ~ .~~~. ~'
             '~'        '~'
             [ tiny-pi-core ]

  ┌──────────────────────────────┐
  │        piCore System         │
  └──────────────────────────────┘
  Hostname:     box
  Kernel:       6.12.25-piCore-v8
  Arch:         aarch64
  Uptime:        1:52
  Load Avg:     0.00 0.00 0.09
  CPU Model:    Raspberry Pi 400 Rev 1.0
  CPU Cores:    4
  RAM Total:    3797.4 MB
  RAM Free:     3461.8 MB

    [Edit]: Added code tags.  Rich
« Last Edit: January 23, 2026, 08:16:21 AM by Rich »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12517
Re: Rust on piCore: Computing π to 10,000 digits
« Reply #2 on: January 23, 2026, 08:16:38 AM »
Hi geev03

Please use  Code Tags  when posting commands and responses seen in a terminal. To use  Code Tags  click on the  #  icon
above the reply box and paste your text between the  Code Tags  as shown in this example:

Quote
[code][   36.176529] pcm512x 1-004d: Failed to get supply 'AVDD': -517
[   36.176536] pcm512x 1-004d: Failed to get supplies: -517
[   36.191753] pcm512x 1-004d: Failed to get supply 'AVDD': -517[/code]

It will appear like this in your post:
Code: [Select]
[   36.176529] pcm512x 1-004d: Failed to get supply 'AVDD': -517
[   36.176536] pcm512x 1-004d: Failed to get supplies: -517
[   36.191753] pcm512x 1-004d: Failed to get supply 'AVDD': -517

Code Tags  serve as visual markers between what you are trying to say and the information you are posting. They also preserve
spacing so column aligned data displays properly. Code tags also automatically add horizontal and or vertical scrollbars
to accommodate long lines and listings.

Offline geev03

  • Wiki Author
  • Newbie
  • *****
  • Posts: 43
Re: Rust on piCore: Computing π to 10,000 digits
« Reply #3 on: January 23, 2026, 09:08:44 AM »
Hi geev03

Please use  Code Tags  when posting commands and responses seen in a terminal. To use  Code Tags  click on the  #  icon
above the reply box and paste your text between the  Code Tags  as shown in this example:


Thank you.

Sysinfo used  is here

Code: [Select]
#!/bin/sh

# Ultra-minimal system info script for piCore / BusyBox
# with TinyCore + Raspberry Pi hybrid ASCII logo

HOST=$(hostname)
KERNEL=$(uname -r)
ARCH=$(uname -m)
UPTIME=$(uptime | sed 's/.*up \([^,]*\),.*/\1/')
LOAD=$(cut -d " " -f1-3 /proc/loadavg)

CPU_MODEL=$(grep "Model" /proc/cpuinfo | head -n1 | cut -d ":" -f2 | sed 's/^ //')
CPU_CORES=$(grep -c "^processor" /proc/cpuinfo)

MEM_TOTAL=$(grep MemTotal /proc/meminfo | awk '{printf "%.1f MB", $2/1024}')
MEM_FREE=$(grep MemAvailable /proc/meminfo | awk '{printf "%.1f MB", $2/1024}')

clear
echo ""
echo "            .~~.   .~~."
echo "           '. \ ' ' / .'"
echo "        .~~ .~~~..~~~. ~~."
echo "       : .~.'~'.~~.'~'.~. :"
echo "      ~ (   ) (  @  ) (   ) ~"
echo "     ( : '~'.~.'~~'.~.'~' : )"
echo "      ~ .~ (   ) ~~ (   ) ~"
echo "       (  : '~' :~~: '~' :  )"
echo "        '~ .~~~. ~  ~ .~~~. ~'"
echo "             '~'        '~'"
echo "             [ tiny-pi-core ]"
echo ""
echo "  ┌──────────────────────────────┐"
echo "  │        piCore System         │"
echo "  └──────────────────────────────┘"
echo "  Hostname:     $HOST"
echo "  Kernel:       $KERNEL"
echo "  Arch:         $ARCH"
echo "  Uptime:       $UPTIME"
echo "  Load Avg:     $LOAD"
echo "  CPU Model:    $CPU_MODEL"
echo "  CPU Cores:    $CPU_CORES"
echo "  RAM Total:    $MEM_TOTAL"
echo "  RAM Free:     $MEM_FREE"
echo ""

Offline geev03

  • Wiki Author
  • Newbie
  • *****
  • Posts: 43
Re: Rust on piCore: Computing π to 10,000 digits
« Reply #4 on: January 23, 2026, 09:51:15 AM »

Outputs π to 10k digits on a Pi 400 without issues. 


Looking again, there is an issue with the code. The value of Pi is NOT "3.92..". Now compiling another code...

Code: [Select]
root@box:/home/tc/pi_calc/target/release# ls
build/             examples/          pi_calc            picorepi.txt
deps/              incremental/       pi_calc.d          picorepi.txt.save
root@box:/home/tc/pi_calc/target/release# ./pi_calc
3.926009437285052832929674253952655321963427871984921170640715706070289694520275370741966576393802824749249195563563914991063978437861359728305354317459983402318064085941521245980071440987892054335406062657458

Offline geev03

  • Wiki Author
  • Newbie
  • *****
  • Posts: 43
Re: Rust on piCore: Computing π to 10,000 digits
« Reply #5 on: January 23, 2026, 11:10:00 AM »
Code: [Select]
use rug::{Float, Integer};
use rug::ops::Pow;

const A: i64 = 13591409;
const B: i64 = 545140134;
const C: i64 = 640320;

fn main() {
    let digits: u32 = 100_000;
    let prec: u32 = (digits as f64 * 3.5) as u32;

With the above code as 'main.rs', it is giving th expected output is finally there ...

root@box:/home/tc/pi_calc2/target/release# ls
Code: [Select]
build/       deps/        examples/    incremental/ pi_calc2     pi_calc2.d
root@box:/home/tc/pi_calc2/target/release# ./pi_calc2
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282

« Last Edit: January 23, 2026, 11:12:26 AM by geev03 »

Offline geev03

  • Wiki Author
  • Newbie
  • *****
  • Posts: 43
Re: Rust on piCore: Computing π to 10,000 digits
« Reply #6 on: January 23, 2026, 12:56:26 PM »
PARI/GP : Value of Pi to a million digits
Code: [Select]
root@box:/tmp# ls
appserr      mc-root/     pari-gp.tcz  pi1m.gp      tags.db      tcloop/
k5_skip      mc-tc/       pari_tcz/    piout.txt    tce/         wm_errors
root@box:/tmp# gp <pi1m.gp
                  GP/PARI CALCULATOR Version 2.17.3 (released)
              arm64 running linux (aarch64 kernel) 64-bit version
              compiled: Jan 23 2026, gcc version 14.2.0 (piCore64)
                            threading engine: single
             (readline not compiled in, extended help not enabled)

                     Copyright (C) 2000-2024 The PARI Group

PARI/GP is free software, covered by the GNU General Public License, and comes
WITHOUT ANY WARRANTY WHATSOEVER.

Type ? for help, \q to quit.
Type ?18 for how to get moral (and possibly technical) support.

parisize = 8000000, primelimit = 1048576, factorlimit = 1048576
  ***   Warning: new stack size = 500000000 (476.837 Mbytes).
   realprecision = 1000016 significant digits (1000000 digits displayed)
Goodbye!
root@box:/tmp#

Formatter output
Code: [Select]
root@box:/tmp# fold -w 100 piout.txt > piout_wrapped.txt

Code: [Select]
default(parisize,500000000)
\p 1000000
myPi = Pi;
write("piout.txt", myPi);
\q


Code: [Select]
root@box:/tmp# ls
appserr            pari-gp.tcz        piout_wrapped.txt  wm_errors
k5_skip            pari_tcz/          tags.db
mc-root/           pi1m.gp            tce/
mc-tc/             piout.txt          tcloop/
root@box:/tmp#


  pari-gp.tcz
Will this be of use ?( Debian etc on rPi can get it as a package)
« Last Edit: January 23, 2026, 01:11:05 PM by geev03 »

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 822
Re: Rust on piCore: Computing π to 10,000 digits
« Reply #7 on: January 23, 2026, 02:42:43 PM »
Code: [Select]
echo 'scale=1000;4*a(1)' | BC_LINE_LENGTH=0 bc -l

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12517
Re: Rust on piCore: Computing π to 10,000 digits
« Reply #8 on: January 23, 2026, 04:17:36 PM »
Hi patrikg
The first 337 characters from your command match the result
posted in reply #5 perfectly.