MLX
 
Loading...
Searching...
No Matches
limits.h
Go to the documentation of this file.
1// Copyright © 2024 Apple Inc.
2#pragma once
3
4#include <limits>
6
7namespace mlx::core {
8
9template <typename T>
11
12template <>
13struct numeric_limits<float> : public std::numeric_limits<float> {};
14
15template <>
17 private:
18 union half_or_bits {
19 uint16_t bits;
20 float16_t value;
21 };
22 constexpr static float16_t bits_to_half(uint16_t v) {
23 return half_or_bits{v}.value;
24 }
25
26 public:
27 constexpr static float16_t lowest() {
28 return bits_to_half(0xFBFF);
29 }
30 static constexpr float16_t max() {
31 return bits_to_half(0x7BFF);
32 }
33 static constexpr float16_t infinity() {
34 return bits_to_half(0x7C00);
35 }
36};
37
38template <>
40 private:
41 union bfloat_or_bits {
42 uint16_t bits;
43 bfloat16_t value;
44 };
45 constexpr static bfloat16_t bits_to_bfloat(uint16_t v) {
46 return bfloat_or_bits{v}.value;
47 }
48
49 public:
50 constexpr static bfloat16_t lowest() {
51 return bits_to_bfloat(0xFF7F);
52 }
53 static constexpr bfloat16_t max() {
54 return bits_to_bfloat(0x7F7F);
55 }
56 static constexpr bfloat16_t infinity() {
57 return bits_to_bfloat(0x7F80);
58 }
59};
60
61} // namespace mlx::core
Definition allocator.h:7
struct _MLX_BFloat16 bfloat16_t
Definition half_types.h:34
struct _MLX_Float16 float16_t
Definition half_types.h:17
static constexpr bfloat16_t max()
Definition limits.h:53
static constexpr bfloat16_t lowest()
Definition limits.h:50
static constexpr bfloat16_t infinity()
Definition limits.h:56
static constexpr float16_t infinity()
Definition limits.h:33
static constexpr float16_t max()
Definition limits.h:30
static constexpr float16_t lowest()
Definition limits.h:27
Definition limits.h:10