negate_builtin.carbon 618 B

123456789101112131415161718192021
  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. // RUN: %{explorer-run}
  7. // RUN: %{explorer-run-trace}
  8. // CHECK:STDOUT: Interface: -3
  9. // CHECK:STDOUT: Op: -3
  10. // CHECK:STDOUT: result: 0
  11. package ExplorerTest api;
  12. fn Main() -> i32 {
  13. var val: i32 = 3;
  14. // Make sure that both the interface and operator work with i32. These rely on
  15. // builtin arithmetic more directly.
  16. Print("Interface: {0}", val.(Negate.Op)());
  17. Print("Op: {0}", -val);
  18. return 0;
  19. }