imate
C++/CUDA Reference
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 
27 SmoothStep::SmoothStep(double alpha_)
28 {
29  this->alpha = alpha_;
30 }
31 
32 
33 // ====================
34 // Smooth Step function (float)
35 // ====================
36 
40 
41 float SmoothStep::function(const float lambda_) const
42 {
43  return 0.5 * (1.0 + tanh(static_cast<float>(this->alpha) * lambda_));
44 }
45 
46 
47 // ====================
48 // Smooth Step function (double)
49 // ====================
50 
54 
55 double SmoothStep::function(const double lambda_) const
56 {
57  return 0.5 * (1.0 + tanh(this->alpha * lambda_));
58 }
59 
60 
61 // ====================
62 // Smooth Step function (long double)
63 // ====================
64 
68 
69 long double SmoothStep::function(const long double lambda_) const
70 {
71  return 0.5 * (1.0 + tanh(static_cast<long double>(this->alpha) * lambda_));
72 }
SmoothStep(double alpha_)
Sets the default for the parameter alpha to 1.0.
Definition: smoothstep.cpp:27
double alpha
Definition: smoothstep.h:57
virtual float function(const float lambda_) const
Definition: smoothstep.cpp:41