greater.carbon 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/primitives.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/float/greater.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/float/greater.carbon
  12. // --- float_greater.carbon
  13. fn Greater(a: f64, b: f64) -> bool = "float.greater";
  14. fn Negate(a: f64) -> f64 = "float.negate";
  15. class True {}
  16. class False {}
  17. fn F(true_: True, false_: False) {
  18. false_ as (if Greater(1.0, 2.0) then True else False);
  19. false_ as (if Greater(1.0, 1.0) then True else False);
  20. true_ as (if Greater(1.0, 0.0) then True else False);
  21. false_ as (if Greater(Negate(1.0), 0.0) then True else False);
  22. true_ as (if Greater(0.0, Negate(1.0)) then True else False);
  23. }
  24. fn RuntimeCallIsValid(a: f64, b: f64) -> bool {
  25. //@dump-sem-ir-begin
  26. return Greater(a, b);
  27. //@dump-sem-ir-end
  28. }
  29. // CHECK:STDOUT: --- float_greater.carbon
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: constants {
  32. // CHECK:STDOUT: %int_64: Core.IntLiteral = int_value 64 [concrete]
  33. // CHECK:STDOUT: %f64.d77: type = class_type @Float, @Float(%int_64) [concrete]
  34. // CHECK:STDOUT: %Greater.type: type = fn_type @Greater [concrete]
  35. // CHECK:STDOUT: %Greater: %Greater.type = struct_value () [concrete]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: imports {
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: fn @RuntimeCallIsValid(%a.param: %f64.d77, %b.param: %f64.d77) -> bool {
  42. // CHECK:STDOUT: !entry:
  43. // CHECK:STDOUT: %Greater.ref: %Greater.type = name_ref Greater, file.%Greater.decl [concrete = constants.%Greater]
  44. // CHECK:STDOUT: %a.ref: %f64.d77 = name_ref a, %a
  45. // CHECK:STDOUT: %b.ref: %f64.d77 = name_ref b, %b
  46. // CHECK:STDOUT: %Greater.call: init bool = call %Greater.ref(%a.ref, %b.ref)
  47. // CHECK:STDOUT: return %Greater.call to %return.param
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: