github.com/apache/arrow/go/v14@v14.0.1/internal/utils/_lib/min_max.c (about) 1 // Licensed to the Apache Software Foundation (ASF) under one 2 // or more contributor license agreements. See the NOTICE file 3 // distributed with this work for additional information 4 // regarding copyright ownership. The ASF licenses this file 5 // to you under the Apache License, Version 2.0 (the 6 // "License"); you may not use this file except in compliance 7 // with the License. You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 #include <arch.h> 18 #include <stdint.h> 19 #include <limits.h> 20 #include <math.h> 21 #include <float.h> 22 23 void FULL_NAME(int8_max_min)(int8_t values[], int len, int8_t* minout, int8_t* maxout) { 24 int8_t max = INT8_MIN; 25 int8_t min = INT8_MAX; 26 27 for (int i = 0; i < len; ++i) { 28 min = min < values[i] ? min : values[i]; 29 max = max > values[i] ? max : values[i]; 30 } 31 32 *maxout = max; 33 *minout = min; 34 } 35 36 void FULL_NAME(uint8_max_min)(uint8_t values[], int len, uint8_t* minout, uint8_t* maxout) { 37 uint8_t max = 0; 38 uint8_t min = UINT8_MAX; 39 40 for (int i = 0; i < len; ++i) { 41 min = min < values[i] ? min : values[i]; 42 max = max > values[i] ? max : values[i]; 43 } 44 45 *maxout = max; 46 *minout = min; 47 } 48 49 void FULL_NAME(int16_max_min)(int16_t values[], int len, int16_t* minout, int16_t* maxout) { 50 int16_t max = INT16_MIN; 51 int16_t min = INT16_MAX; 52 53 for (int i = 0; i < len; ++i) { 54 min = min < values[i] ? min : values[i]; 55 max = max > values[i] ? max : values[i]; 56 } 57 58 *maxout = max; 59 *minout = min; 60 } 61 62 void FULL_NAME(uint16_max_min)(uint16_t values[], int len, uint16_t* minout, uint16_t* maxout) { 63 uint16_t max = 0; 64 uint16_t min = UINT16_MAX; 65 66 for (int i = 0; i < len; ++i) { 67 min = min < values[i] ? min : values[i]; 68 max = max > values[i] ? max : values[i]; 69 } 70 71 *maxout = max; 72 *minout = min; 73 } 74 75 void FULL_NAME(int32_max_min)(int32_t values[], int len, int32_t* minout, int32_t* maxout) { 76 int32_t max = INT32_MIN; 77 int32_t min = INT32_MAX; 78 79 for (int i = 0; i < len; ++i) { 80 min = min < values[i] ? min : values[i]; 81 max = max > values[i] ? max : values[i]; 82 } 83 84 *maxout = max; 85 *minout = min; 86 } 87 88 void FULL_NAME(uint32_max_min)(uint32_t values[], int len, uint32_t* minout, uint32_t* maxout) { 89 uint32_t max = 0; 90 uint32_t min = UINT32_MAX; 91 92 for (int i = 0; i < len; ++i) { 93 min = min < values[i] ? min : values[i]; 94 max = max > values[i] ? max : values[i]; 95 } 96 97 *maxout = max; 98 *minout = min; 99 } 100 101 void FULL_NAME(int64_max_min)(int64_t values[], int len, int64_t* minout, int64_t* maxout) { 102 int64_t max = INT64_MIN; 103 int64_t min = INT64_MAX; 104 105 for (int i = 0; i < len; ++i) { 106 min = min < values[i] ? min : values[i]; 107 max = max > values[i] ? max : values[i]; 108 } 109 110 *maxout = max; 111 *minout = min; 112 } 113 114 void FULL_NAME(uint64_max_min)(uint64_t values[], int len, uint64_t* minout, uint64_t* maxout) { 115 uint64_t max = 0; 116 uint64_t min = UINT64_MAX; 117 118 for (int i = 0; i < len; ++i) { 119 min = min < values[i] ? min : values[i]; 120 max = max > values[i] ? max : values[i]; 121 } 122 123 *maxout = max; 124 *minout = min; 125 }