Skip to content

Double.Pi question #82

@jacobmadsen

Description

@jacobmadsen

I find your library very interesting and am trying to understand the choice of arithmetic in the library. I am focusing on PI, since it is a commonly known value.

Do you mind explaining how Double.Pi was settled? Double.fromString(PI) almost produces the exact same result.

I can see the fromString method iterates over multiple static Double methods which accumulates to a significant different residual part (lo) compared to the actual decimals of the low part of PI:
2.384626433832795e-16 (the PI.slice(17, 33) seen below).

const PI = '3.141592653589793238462643383279502884'
Double.Pi // { hi: 3.141592653589793, lo: 1.2246467991473532e-16 }

Double.fromString(PI) // { hi: 3.141592653589793, lo: 1.224646799147353e-16 }

const high = Number.parseFloat(PI.slice(0, 17)) // 3.141592653589793
const low = Number.parseFloat(PI.slice(17, 33) + 'e-31') // 2.384626433832795e-16

twoSum(high, low) // { hi: 3.1415926535897936, lo: -2.056265664667831e-16 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions