numeric_literals.carbon 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. // AUTOUPDATE
  6. fn F() {
  7. // 8 and 9 trigger special behavior in APInt when mishandling signed versus
  8. // unsigned, so we pay extra attention to those.
  9. var ints: [i32; 5] = (
  10. 8,
  11. 9,
  12. 0x8,
  13. 0b1000,
  14. 39999999999999999993,
  15. );
  16. var floats: [f64; 7] = (
  17. 0.9,
  18. 8.0,
  19. 80.0,
  20. 1.0e7,
  21. 1.0e8,
  22. 1.0e-8,
  23. 39999999999999999993.0e39999999999999999993,
  24. );
  25. }
  26. // CHECK:STDOUT: file "numeric_literals.carbon" {
  27. // CHECK:STDOUT: %.loc7 = fn_decl @F
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: fn @F() {
  31. // CHECK:STDOUT: !entry:
  32. // CHECK:STDOUT: %.loc10_19: i32 = int_literal 5
  33. // CHECK:STDOUT: %.loc10_20: type = array_type %.loc10_19, i32
  34. // CHECK:STDOUT: %ints: ref [i32; 5] = var "ints"
  35. // CHECK:STDOUT: %.loc11_5.1: i32 = int_literal 8
  36. // CHECK:STDOUT: %.loc11_5.2: i32 = stub_reference %.loc11_5.1
  37. // CHECK:STDOUT: %.loc12_5.1: i32 = int_literal 9
  38. // CHECK:STDOUT: %.loc12_5.2: i32 = stub_reference %.loc12_5.1
  39. // CHECK:STDOUT: %.loc13_5.1: i32 = int_literal 8
  40. // CHECK:STDOUT: %.loc13_5.2: i32 = stub_reference %.loc13_5.1
  41. // CHECK:STDOUT: %.loc14_5.1: i32 = int_literal 8
  42. // CHECK:STDOUT: %.loc14_5.2: i32 = stub_reference %.loc14_5.1
  43. // CHECK:STDOUT: %.loc15_5.1: i32 = int_literal 39999999999999999993
  44. // CHECK:STDOUT: %.loc15_5.2: i32 = stub_reference %.loc15_5.1
  45. // CHECK:STDOUT: %.loc16_3.1: type = tuple_type (i32, i32, i32, i32, i32)
  46. // CHECK:STDOUT: %.loc16_3.2: (i32, i32, i32, i32, i32) = tuple_literal (%.loc11_5.2, %.loc12_5.2, %.loc13_5.2, %.loc14_5.2, %.loc15_5.2)
  47. // CHECK:STDOUT: %.loc16_3.3: [i32; 5] = array_value %.loc16_3.2
  48. // CHECK:STDOUT: assign %ints, %.loc16_3.3
  49. // CHECK:STDOUT: %.loc17_21: i32 = int_literal 7
  50. // CHECK:STDOUT: %.loc17_22: type = array_type %.loc17_21, f64
  51. // CHECK:STDOUT: %floats: ref [f64; 7] = var "floats"
  52. // CHECK:STDOUT: %.loc18_5.1: f64 = real_literal 9e-1
  53. // CHECK:STDOUT: %.loc18_5.2: f64 = stub_reference %.loc18_5.1
  54. // CHECK:STDOUT: %.loc19_5.1: f64 = real_literal 80e-1
  55. // CHECK:STDOUT: %.loc19_5.2: f64 = stub_reference %.loc19_5.1
  56. // CHECK:STDOUT: %.loc20_5.1: f64 = real_literal 800e-1
  57. // CHECK:STDOUT: %.loc20_5.2: f64 = stub_reference %.loc20_5.1
  58. // CHECK:STDOUT: %.loc21_5.1: f64 = real_literal 10e6
  59. // CHECK:STDOUT: %.loc21_5.2: f64 = stub_reference %.loc21_5.1
  60. // CHECK:STDOUT: %.loc22_5.1: f64 = real_literal 10e7
  61. // CHECK:STDOUT: %.loc22_5.2: f64 = stub_reference %.loc22_5.1
  62. // CHECK:STDOUT: %.loc23_5.1: f64 = real_literal 10e-9
  63. // CHECK:STDOUT: %.loc23_5.2: f64 = stub_reference %.loc23_5.1
  64. // CHECK:STDOUT: %.loc24_5.1: f64 = real_literal 399999999999999999930e39999999999999999992
  65. // CHECK:STDOUT: %.loc24_5.2: f64 = stub_reference %.loc24_5.1
  66. // CHECK:STDOUT: %.loc25_3.1: type = tuple_type (f64, f64, f64, f64, f64, f64, f64)
  67. // CHECK:STDOUT: %.loc25_3.2: (f64, f64, f64, f64, f64, f64, f64) = tuple_literal (%.loc18_5.2, %.loc19_5.2, %.loc20_5.2, %.loc21_5.2, %.loc22_5.2, %.loc23_5.2, %.loc24_5.2)
  68. // CHECK:STDOUT: %.loc25_3.3: [f64; 7] = array_value %.loc25_3.2
  69. // CHECK:STDOUT: assign %floats, %.loc25_3.3
  70. // CHECK:STDOUT: return
  71. // CHECK:STDOUT: }