mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
math: move the math.mathutil
generic min
/max
/abs
fns to math
(#13042)
This commit is contained in:
@ -4,36 +4,48 @@
|
||||
module util
|
||||
|
||||
// imin returns the smallest of two integer values
|
||||
[deprecated: 'use math.min instead']
|
||||
[deprecated_after: '2022-01-19']
|
||||
[inline]
|
||||
pub fn imin(a int, b int) int {
|
||||
return if a < b { a } else { b }
|
||||
}
|
||||
|
||||
// imin returns the biggest of two integer values
|
||||
[deprecated: 'use math.max instead']
|
||||
[deprecated_after: '2022-01-19']
|
||||
[inline]
|
||||
pub fn imax(a int, b int) int {
|
||||
return if a > b { a } else { b }
|
||||
}
|
||||
|
||||
// iabs returns an integer as absolute value
|
||||
[deprecated: 'use math.abs instead']
|
||||
[deprecated_after: '2022-01-19']
|
||||
[inline]
|
||||
pub fn iabs(v int) int {
|
||||
return if v > 0 { v } else { -v }
|
||||
}
|
||||
|
||||
// umin returns the smallest of two u32 values
|
||||
[deprecated: 'use math.min instead']
|
||||
[deprecated_after: '2022-01-19']
|
||||
[inline]
|
||||
pub fn umin(a u32, b u32) u32 {
|
||||
return if a < b { a } else { b }
|
||||
}
|
||||
|
||||
// umax returns the biggest of two u32 values
|
||||
[deprecated: 'use math.max instead']
|
||||
[deprecated_after: '2022-01-19']
|
||||
[inline]
|
||||
pub fn umax(a u32, b u32) u32 {
|
||||
return if a > b { a } else { b }
|
||||
}
|
||||
|
||||
// uabs returns an u32 as absolute value
|
||||
[deprecated: 'use math.abs instead']
|
||||
[deprecated_after: '2022-01-19']
|
||||
[inline]
|
||||
pub fn uabs(v u32) u32 {
|
||||
return if v > 0 { v } else { -v }
|
||||
@ -41,6 +53,8 @@ pub fn uabs(v u32) u32 {
|
||||
|
||||
// fmin_32 returns the smallest `f32` of input `a` and `b`.
|
||||
// Example: assert fmin_32(2.0,3.0) == 2.0
|
||||
[deprecated: 'use math.min instead']
|
||||
[deprecated_after: '2022-01-19']
|
||||
[inline]
|
||||
pub fn fmin_32(a f32, b f32) f32 {
|
||||
return if a < b { a } else { b }
|
||||
@ -48,6 +62,8 @@ pub fn fmin_32(a f32, b f32) f32 {
|
||||
|
||||
// fmax_32 returns the largest `f32` of input `a` and `b`.
|
||||
// Example: assert fmax_32(2.0,3.0) == 3.0
|
||||
[deprecated: 'use math.max instead']
|
||||
[deprecated_after: '2022-01-19']
|
||||
[inline]
|
||||
pub fn fmax_32(a f32, b f32) f32 {
|
||||
return if a > b { a } else { b }
|
||||
@ -55,6 +71,8 @@ pub fn fmax_32(a f32, b f32) f32 {
|
||||
|
||||
// fabs_32 returns the absolute value of `a` as a `f32` value.
|
||||
// Example: assert fabs_32(-2.0) == 2.0
|
||||
[deprecated: 'use math.abs instead']
|
||||
[deprecated_after: '2022-01-19']
|
||||
[inline]
|
||||
pub fn fabs_32(v f32) f32 {
|
||||
return if v > 0 { v } else { -v }
|
||||
@ -62,6 +80,8 @@ pub fn fabs_32(v f32) f32 {
|
||||
|
||||
// fmin_64 returns the smallest `f64` of input `a` and `b`.
|
||||
// Example: assert fmin_64(2.0,3.0) == 2.0
|
||||
[deprecated: 'use math.min instead']
|
||||
[deprecated_after: '2022-01-19']
|
||||
[inline]
|
||||
pub fn fmin_64(a f64, b f64) f64 {
|
||||
return if a < b { a } else { b }
|
||||
@ -69,6 +89,8 @@ pub fn fmin_64(a f64, b f64) f64 {
|
||||
|
||||
// fmax_64 returns the largest `f64` of input `a` and `b`.
|
||||
// Example: assert fmax_64(2.0,3.0) == 3.0
|
||||
[deprecated: 'use math.max instead']
|
||||
[deprecated_after: '2022-01-19']
|
||||
[inline]
|
||||
pub fn fmax_64(a f64, b f64) f64 {
|
||||
return if a > b { a } else { b }
|
||||
@ -76,6 +98,8 @@ pub fn fmax_64(a f64, b f64) f64 {
|
||||
|
||||
// fabs_64 returns the absolute value of `a` as a `f64` value.
|
||||
// Example: assert fabs_64(-2.0) == f64(2.0)
|
||||
[deprecated: 'use math.abs instead']
|
||||
[deprecated_after: '2022-01-19']
|
||||
[inline]
|
||||
pub fn fabs_64(v f64) f64 {
|
||||
return if v > 0 { v } else { -v }
|
||||
|
Reference in New Issue
Block a user