Search code examples
gocompiler-optimizationconstantfolding

does golang compiler use constant folding?


just wondering if "go" compiler uses any sort of optimization such as constant folding.

https://en.wikipedia.org/wiki/Constant_folding

searched through google but couldn't find the answer i'm looking for.


Solution

  • Constant folding - Wikipedia

    Constant folding is the process of recognizing and evaluating constant expressions at compile time rather than computing them at runtime.


    The Go Programming Language Specification

    Constant expressions

    Constant expressions may contain only constant operands and are evaluated at compile time.


    Package big

    import "math/big"
    

    Package big implements arbitrary-precision arithmetic (big numbers).


    Go constant expressions are evaluated at compile time. The Go gc compiler, written in Go, uses package big to evaluate numeric constant expressions.