Below you will find pages that utilize the taxonomy term “arithmetic”

February 24, 2024

# Generating the Fibonacci sequence on a Raspberry Pi 5

Linux includes a bench calculator called bc, which can achieve remarkable arbitrary-precision results in very few lines of code. For ease of running, code can be embedded in a here document:
fib.sh
#!/usr/bin/env bash BC_LINE_LENGTH=0 bc -q <<end 0;1; for (i=1;i<1000;i++) {g=last;last+=f;f=g;last} end The BC_LINE_LENGTH environment variable is used to prevent long lines from being split with a \ continuation character.
The -q flag suppresses the welcome prompt.
The 0;1; bit just prints the first two results.

read moreApril 1, 2018

# Epic Number Battles of History: Swift 3 vs Python

Swift 3 has a “decimal” number type that can represent values such as 0.3 that are inexactly represented in Double or Float types. According to this article:
An instance can represent any number that can be expressed as mantissa x 10^exponent where mantissa is a decimal integer up to 38 digits long, and exponent is an integer from –128 through 127.
Note this is not the same as Python’s arbitrary-precision integer arithmetic.

read more