mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 09:34:42 +01:00
Make Core.Float a class. Add missing builtins for float support. (#5932)
Add missing builtins for float compound assignment, for building a FloatType, and for converting a float literal to FloatType. Switch `Core.Float` to being a class and add impls for the various floating-point operators. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
This commit is contained in:
co-authored by
google-labs-jules[bot]
Carbon Infra Bot
parent
f616817b71
commit
694c00c7eb
+18
-1
@@ -2,12 +2,29 @@
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/as.carbon
|
||||
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/float_literal.carbon
|
||||
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/parts/int_literal.carbon
|
||||
|
||||
// --- min_prelude/parts/float.carbon
|
||||
|
||||
package Core library "prelude/parts/float";
|
||||
|
||||
export import library "prelude/parts/as";
|
||||
export import library "prelude/parts/float_literal";
|
||||
export import library "prelude/parts/int_literal";
|
||||
|
||||
fn Float(size: IntLiteral()) -> type = "float.make_type";
|
||||
private fn MakeFloat(size: IntLiteral()) -> type = "float.make_type";
|
||||
|
||||
class Float(N:! IntLiteral()) {
|
||||
adapt MakeFloat(N);
|
||||
}
|
||||
|
||||
impl forall [To:! IntLiteral()] FloatLiteral() as ImplicitAs(Float(To)) {
|
||||
fn Convert[self: Self]() -> Float(To) = "float.convert_checked";
|
||||
}
|
||||
|
||||
// TODO: Remove this once ImplicitAs extends As.
|
||||
impl forall [To:! IntLiteral()] FloatLiteral() as As(Float(To)) {
|
||||
fn Convert[self: Self]() -> Float(To) = "float.convert_checked";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
// --- min_prelude/parts/float_literal.carbon
|
||||
|
||||
package Core library "prelude/parts/float_literal";
|
||||
|
||||
fn FloatLiteral() -> type = "float_literal.make_type";
|
||||
Reference in New Issue
Block a user