-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathchapter12_02-002_area_of_circle.cpp
More file actions
35 lines (28 loc) · 1008 Bytes
/
chapter12_02-002_area_of_circle.cpp
File metadata and controls
35 lines (28 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2025.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// chapter12_02-002_area_of_circle.cpp
#include <cmath>
#include <concepts>
#include <limits>
#include <iomanip>
#include <iostream>
#include <numbers>
#include <sstream>
template<typename T>
requires std::floating_point<T>
constexpr auto area_of_a_circle(T r) -> T
{
return (std::numbers::pi_v<T> * r) * r;
}
auto main() -> int;
auto main() -> int
{
std::stringstream strm { };
strm << "area_of_a_circle(0.5F): " << std::fixed << std::setprecision(std::numeric_limits<float>::digits10) << area_of_a_circle(0.5F) << '\n';
strm << "area_of_a_circle(1.5) : " << std::fixed << std::setprecision(std::numeric_limits<double>::digits10) << area_of_a_circle(1.5) << '\n';
std::cout << strm.str() << std::endl;
}