Skip to content

[libc] Add float.h header. #78737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/config/baremetal/arm/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.ctype
libc.include.fenv
libc.include.errno
libc.include.float
libc.include.inttypes
libc.include.math
libc.include.stdio
Expand Down
1 change: 1 addition & 0 deletions libc/config/baremetal/riscv/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.ctype
libc.include.fenv
libc.include.errno
libc.include.float
libc.include.inttypes
libc.include.math
libc.include.stdio
Expand Down
1 change: 1 addition & 0 deletions libc/config/darwin/arm/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.ctype
libc.include.errno
libc.include.fenv
libc.include.float
libc.include.inttypes
libc.include.math
libc.include.stdlib
Expand Down
1 change: 1 addition & 0 deletions libc/config/darwin/x86_64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.errno
# Fenv is currently disabled.
#libc.include.fenv
libc.include.float
libc.include.inttypes
libc.include.math
libc.include.stdlib
Expand Down
1 change: 1 addition & 0 deletions libc/config/gpu/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.assert
libc.include.ctype
libc.include.string
libc.include.float
libc.include.inttypes
libc.include.math
libc.include.fenv
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.errno
libc.include.features
libc.include.fenv
libc.include.float
libc.include.inttypes
libc.include.math
libc.include.pthread
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/arm/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.ctype
libc.include.fenv
libc.include.errno
libc.include.float
libc.include.inttypes
libc.include.math
libc.include.stdlib
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.fcntl
libc.include.features
libc.include.fenv
libc.include.float
libc.include.inttypes
libc.include.math
libc.include.pthread
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.fcntl
libc.include.features
libc.include.fenv
libc.include.float
libc.include.inttypes
libc.include.math
libc.include.pthread
Expand Down
8 changes: 8 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ add_gen_header(
.llvm-libc-types.imaxdiv_t
)

add_gen_header(
float
DEF_FILE float.h.def
GEN_HDR float.h
DEPENDS
.llvm-libc-macros.float_macros
)

add_gen_header(
math
DEF_FILE math.h.def
Expand Down
14 changes: 14 additions & 0 deletions libc/include/float.h.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//===-- C standard library header float.h ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_FLOAT_H
#define LLVM_LIBC_FLOAT_H

#include <llvm-libc-macros/float-macros.h>

#endif // LLVM_LIBC_FLOAT_H
6 changes: 6 additions & 0 deletions libc/include/llvm-libc-macros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ add_macro_header(
file-seek-macros.h
)

add_macro_header(
float_macros
HDR
float-macros.h
)

add_macro_header(
math_macros
HDR
Expand Down
21 changes: 21 additions & 0 deletions libc/include/llvm-libc-macros/float-macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Definition of macros from float.h ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef __LLVM_LIBC_MACROS_FLOAT_MACROS_H
#define __LLVM_LIBC_MACROS_FLOAT_MACROS_H

#undef FLT_MANT_DIG
#define FLT_MANT_DIG __FLT_MANT_DIG__

#undef DBL_MANT_DIG
#define DBL_MANT_DIG __DBL_MANT_DIG__

#undef LDBL_MANT_DIG
#define LDBL_MANT_DIG __LDBL_MANT_DIG__

#endif // __LLVM_LIBC_MACROS_FLOAT_MACROS_H
10 changes: 10 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,15 @@ def StdC : StandardSpec<"stdc"> {
]
>;

HeaderSpec Float = HeaderSpec<
"float.h",
[
Macro<"FLT_MANT_DIG">,
Macro<"DBL_MANT_DIG">,
Macro<"LDBL_MANT_DIG">,
]
>;

NamedType SigAtomicT = NamedType<"sig_atomic_t">;
HeaderSpec Signal = HeaderSpec<
"signal.h",
Expand Down Expand Up @@ -1149,6 +1158,7 @@ def StdC : StandardSpec<"stdc"> {
CType,
Errno,
Fenv,
Float,
Math,
String,
StdIO,
Expand Down