imate
C++/CUDA Reference
Loading...
Searching...
No Matches
smoothstep.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
3 * SPDX-License-Identifier: BSD-3-Clause
4 * SPDX-FileType: SOURCE
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the license found in the LICENSE.txt file in the root
8 * directory of this source tree.
9 */
10
11
12// =======
13// Headers
14// =======
15
16#include <cmath> // tanh
17#include "./smoothstep.h"
18
19
20// ===========
21// Smooth Step
22// ===========
23
26
28{
29 this->alpha = alpha_;
30}
31
32
33// ====================
34// Smooth Step function (float)
35// ====================
36
40
41float SmoothStep::function(const float lambda_) const
42{
43 return 0.5f * (1.0f + std::tanh(
44 static_cast<float>(this->alpha) * lambda_));
45}
46
47
48// ====================
49// Smooth Step function (double)
50// ====================
51
55
56double SmoothStep::function(const double lambda_) const
57{
58 return 0.5 * (1.0 + std::tanh(this->alpha * lambda_));
59}
60
61
62// ====================
63// Smooth Step function (long double)
64// ====================
65
69
70long double SmoothStep::function(const long double lambda_) const
71{
72 return 0.5l * (1.0l + std::tanh(
73 static_cast<long double>(this->alpha) * lambda_));
74}
SmoothStep(double alpha_)
Sets the default for the parameter alpha to 1.0.
double alpha
Definition smoothstep.h:57
virtual float function(const float lambda_) const