---
title: v?fmax
description: "矢量计算最大值函数，输入为向量。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0132.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0132.html
indexId: 0077ca1f761bde77aad9045adc907f54ad2b2e93b831a02354226cf628bbaaae61
---
# v?fmax

矢量计算最大值函数，输入为向量。

#### 接口定义

C interface：

void vsfmax(const int len, const float* src1, const float* src2, float* dst);

void vdfmax(const int len, const double* src1, const double* src2, double* dst);

void vhfmax(const int len, const __fp16 *src1, const __fp16 *src2, __fp16 *dst);


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| len | 整型数 | 表示输入向量的元素个数。 len≤0时会提示参数len无效并返回。 | 输入 |
| src1 | 在vsfmax中是单精度浮点类型。 在vdfmax中是双精度浮点类型。 vhfmax中是半精度浮点类型。 | 输入向量src1，向量长度为len。 若为空指针，会提示空指针错误并返回。 | 输入 |
| src2 | 在vsfmax中是单精度浮点类型。 在vdfmax中是双精度浮点类型。 vhfmax中是半精度浮点类型。 | 输入向量src2，向量长度为len。 若为空指针，会提示空指针错误并返回。 | 输入 |
| dst | 在vsfmax中是单精度浮点类型。 在vdfmax中是双精度浮点类型。 vhfmax中是半精度浮点类型。 | 输出dst，向量长度为len。 若为空指针，会提示空指针错误并返回。 | 输出 |


#### 输出结果

- 每个运算值返回：x > y，返回x，否则返回y。
- 其他特殊值参考如下说明。| 输入值（src1） | 输入值（src2） | 输出值（dst） |
| --- | --- | --- |
| any | qnan | x |
| qnan | any | y |
| any | snan | nan |
| snan | any | nan |


#### 依赖

C: "kvml.h"


#### 示例

C interface：

```
int i, len = 8; 
    float src1[8] = {-1.5f, -0.0f, 0.0f, 1.0f, 1.5f, -INFINITY, INFINITY, NAN};
    float src2[8] = {-1.1f, 0.0f, +0.0f, -1.0f, -1.5f, +INFINITY, -INFINITY, -NAN}; 
    float* dst = (float*)malloc(sizeof(float) * len); 
    if (dst == NULL) { 
        printf("Malloc Failed!\n"); 
        return 0;
    }
    vsfmax(len, src1, src2, dst);

    /** 
     *  Output dst: 
     *     -1.100000 0.000000 0.000000 1.000000 1.500000 inf inf nan
     */
```
