[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / AST / const-fpfeatures.cpp
blob9c807b34625f3a03f245de4e0342b205bf569894
1 // RUN: %clang_cc1 -S -emit-llvm -triple i386-linux -std=c++2a -Wno-unknown-pragmas %s -o - | FileCheck %s
3 // nextUp(1.F) == 0x1.000002p0F
5 constexpr float add_round_down(float x, float y) {
6 #pragma STDC FENV_ROUND FE_DOWNWARD
7 float res = x;
8 res += y;
9 return res;
12 constexpr float add_round_up(float x, float y) {
13 #pragma STDC FENV_ROUND FE_UPWARD
14 float res = x;
15 res += y;
16 return res;
19 float V1 = add_round_down(1.0F, 0x0.000001p0F);
20 float V2 = add_round_up(1.0F, 0x0.000001p0F);
21 // CHECK: @V1 = {{.*}} float 1.000000e+00
22 // CHECK: @V2 = {{.*}} float 0x3FF0000020000000
24 constexpr float add_cast_round_down(float x, double y) {
25 #pragma STDC FENV_ROUND FE_DOWNWARD
26 float res = x;
27 res += y;
28 return res;
31 constexpr float add_cast_round_up(float x, double y) {
32 #pragma STDC FENV_ROUND FE_UPWARD
33 float res = x;
34 res += y;
35 return res;
38 float V3 = add_cast_round_down(1.0F, 0x0.000001p0F);
39 float V4 = add_cast_round_up(1.0F, 0x0.000001p0F);
41 // CHECK: @V3 = {{.*}} float 1.000000e+00
42 // CHECK: @V4 = {{.*}} float 0x3FF0000020000000
44 // The next three variables use the same function as initializer, only rounding
45 // modes differ.
47 float V5 = []() -> float {
48 return [](float x, float y)->float {
49 #pragma STDC FENV_ROUND FE_UPWARD
50 return x + y;
51 }([](float x, float y) -> float {
52 #pragma STDC FENV_ROUND FE_UPWARD
53 return x + y;
54 }(1.0F, 0x0.000001p0F),
55 0x0.000001p0F);
56 }();
57 // CHECK: @V5 = {{.*}} float 0x3FF0000040000000
59 float V6 = []() -> float {
60 return [](float x, float y)->float {
61 #pragma STDC FENV_ROUND FE_DOWNWARD
62 return x + y;
63 }([](float x, float y) -> float {
64 #pragma STDC FENV_ROUND FE_UPWARD
65 return x + y;
66 }(1.0F, 0x0.000001p0F),
67 0x0.000001p0F);
68 }();
69 // CHECK: @V6 = {{.*}} float 0x3FF0000020000000
71 float V7 = []() -> float {
72 return [](float x, float y)->float {
73 #pragma STDC FENV_ROUND FE_DOWNWARD
74 return x + y;
75 }([](float x, float y) -> float {
76 #pragma STDC FENV_ROUND FE_DOWNWARD
77 return x + y;
78 }(1.0F, 0x0.000001p0F),
79 0x0.000001p0F);
80 }();
81 // CHECK: @V7 = {{.*}} float 1.000000e+00