在 Visual C++ 中使用 sqrt 和 pow 函数

您所在的位置:网站首页 c语言中pow的使用 在 Visual C++ 中使用 sqrt 和 pow 函数

在 Visual C++ 中使用 sqrt 和 pow 函数

2024-01-05 20:17| 来源: 网络整理| 查看: 265

在 Visual C++ 中使用 STL sqrt 和 pow 函数 项目 07/17/2023

本文说明如何在 Visual C++ 中使用 STL sqrt 和 pow 函数。 本文中的信息仅适用于非托管 Visual C++ 代码。

原始产品版本: Visual C++ 原始 KB 编号: 157942

必需的标头 原型 // sqrt template inline valarray sqrt(const valarray& x); // pow template inline valarray pow(const valarray& x, const valarray& y); template inline valarray pow(const valarray x, const T& y); template inline valarray pow(const T& x, const valarray& y);

注意

原型中的类/参数名称可能与头文件中的版本不匹配。 某些已修改以提高可读性。

说明

本文通过示例代码说明 STL sqrt() 和 pow() 函数的使用。 sqrt() 返回 类 的对象,其每个元素在索引 I 处是 的 x[I]平方根。 pow() 具有三个模板函数。 第一个模板函数返回 类 valarray的对象,其每个元素在索引 I 处的元素都 x[I] 提升为 的 y[I]幂。 第二个模板函数存储在元素 I 中, x[I] 提升到 y 的幂。 第三个模板函数存储在元素 I x 中,提升到 的 y[I]幂。 有关 和 pow的sqrt相同信息,请访问 sqrt 和 pow。

示例代码 ////////////////////////////////////////////////////////////////////// // Compile options needed: /GX // main.cpp : Illustrates the use of STL sqrt() and pow() functions. // Functions: // sqrt, pow // of Microsoft Product Support Services, // Copyright (c) 1996 Microsoft Corporation. All rights reserved. ////////////////////////////////////////////////////////////////////// #include // for i/o functions #include // for valarray #include // for sqrt() and pow() #if _MSC_VER > 1020 // if VC++ version is > 4.2 using namespace std; // std c++ libs implemented in std #endif #define ARRAY_SIZE 3 // array size void main() { // Set val_array to contain values 1, 4, 9 for the following test valarray val_array(ARRAY_SIZE); for (int i = 0; i < ARRAY_SIZE; i++) val_array[i] = (i+1) * (i+1); // Display the size of val_array cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3