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 <>
16struct numeric_limits<double> : public std::numeric_limits<double> {};
17
18template <>
20 private:
21 union half_or_bits {
22 uint16_t bits;
23 float16_t value;
24 };
25 constexpr static float16_t bits_to_half(uint16_t v) {
26 return half_or_bits{v}.value;
27 }
28
29 public:
30 constexpr static float16_t lowest() {
31 return bits_to_half(0xFBFF);
32 }
33 static constexpr float16_t max() {
34 return bits_to_half(0x7BFF);
35 }
36 static constexpr float16_t infinity() {
37 return bits_to_half(0x7C00);
38 }
39};
40
41template <>
43 private:
44 union bfloat_or_bits {
45 uint16_t bits;
46 bfloat16_t value;
47 };
48 constexpr static bfloat16_t bits_to_bfloat(uint16_t v) {
49 return bfloat_or_bits{v}.value;
50 }
51
52 public:
53 constexpr static bfloat16_t lowest() {
54 return bits_to_bfloat(0xFF7F);
55 }
56 static constexpr bfloat16_t max() {
57 return bits_to_bfloat(0x7F7F);
58 }
59 static constexpr bfloat16_t infinity() {
60 return bits_to_bfloat(0x7F80);
61 }
62};
63
64} // 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:56
static constexpr bfloat16_t lowest()
Definition limits.h:53
static constexpr bfloat16_t infinity()
Definition limits.h:59
static constexpr float16_t infinity()
Definition limits.h:36
static constexpr float16_t max()
Definition limits.h:33
static constexpr float16_t lowest()
Definition limits.h:30
Definition limits.h:10