Flutter Engine
The Flutter Engine
lib
ui
floating_point.h
Go to the documentation of this file.
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#ifndef FLUTTER_LIB_UI_FLOATING_POINT_H_
6
#define FLUTTER_LIB_UI_FLOATING_POINT_H_
7
8
#include <algorithm>
9
#include <limits>
10
11
namespace
flutter
{
12
13
/// Converts a double to a float, truncating finite values that are larger than
14
/// FLT_MAX or smaller than FLT_MIN to those values.
15
static
float
SafeNarrow
(
double
value
) {
16
if
(std::isinf(
value
) || std::isnan(
value
)) {
17
return
static_cast<
float
>
(
value
);
18
}
else
{
19
// Avoid truncation to inf/-inf.
20
return
std::clamp
(
static_cast<
float
>
(
value
),
21
std::numeric_limits<float>::lowest(),
22
std::numeric_limits<float>::max
());
23
}
24
}
25
26
}
// namespace flutter
27
28
#endif
// FLUTTER_LIB_UI_FLOATING_POINT_H_
clamp
static unsigned clamp(SkFixed fx, int max)
Definition:
SkBitmapProcState_matrixProcs.cpp:271
value
uint8_t value
Definition:
fl_standard_message_codec.cc:36
max
static float max(float r, float g, float b)
Definition:
hsl.cpp:49
flutter
Definition:
asset_manager.cc:10
flutter::SafeNarrow
static float SafeNarrow(double value)
Definition:
floating_point.h:15
Generated on Sun Jun 23 2024 21:55:05 for Flutter Engine by
1.9.4