Skip to content

bcpl64: constant folding does not work for 64 bit expressions #2

@dgottner

Description

@dgottner

I've used BCPL for many 64 bit Project Euler problems, but I've noticed an issue when compile-time expressions exceed 32 bits; the results are incorrect. Here is an example:

GET "libhdr"

LET start() = VALOF {
    LET x = ?
    x := 999 * 10_000_000
    writef("x = %d *n", x)
    x := 999
    x *:= 10_000_000
    writef("x = %d *n", x)
    RESULTIS 0
}

Using bcpl64 compile, the output is:

x = 14284967296
x = 9990000000

The first result, where the compiler did constant folding is wrong. The second result, where the the calculation was done at runtime is correct.

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