-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Must a const fn behave exactly the same at runtime as at compile-time? #77745
Copy link
Copy link
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-floating-pointArea: Floating point numbers and arithmeticArea: Floating point numbers and arithmeticC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-floating-pointArea: Floating point numbers and arithmeticArea: Floating point numbers and arithmeticC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
TLDR: should we allow floating point types in const fn?
Basically the question is whether the following const fn
must yield the same results for the same arguments if it is invoked at runtime or compile-time:
Depending on the platform's NaN behavior, the result will differ between runtime and compile-time execution of
foo(1.0, 0.0). Compile-time execution is determined by the Rust port of apfloat (a soft-float implementation); runtime behavior depends on the actual NaN patterns used by the hardware which are not always fully determined by the IEEE specification.Note that this is entirely independent of any optimizations; we are discussing here the relationship between code that the user explicitly requests to be executed at compile-time, and regular run-time code. Optimizations apply to all code equally and they treat
fnandconst fnthe same, so the the questions of how floating-point operations can be optimized is an entirely separate from and off-topic for this issue.cc @rust-lang/wg-const-eval