Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
math: add more C. fn overrides, for the default C backend (speed up e…
…xamples/path_tracing.v) (#19271)
- Loading branch information
Showing
13 changed files
with
131 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module math | ||
|
||
fn C.exp(x f64) f64 | ||
|
||
fn C.exp2(x f64) f64 | ||
|
||
fn C.ldexp(x f64, exp int) f64 | ||
|
||
// exp returns e**x, the base-e exponential of x. | ||
[inline] | ||
pub fn exp(x f64) f64 { | ||
return C.exp(x) | ||
} | ||
|
||
// exp2 returns 2**x, the base-2 exponential of x. | ||
[inline] | ||
pub fn exp2(x f64) f64 { | ||
return C.exp2(x) | ||
} | ||
|
||
// ldexp calculates frac*(2**exp). | ||
[inline] | ||
pub fn ldexp(frac f64, exp int) f64 { | ||
return C.ldexp(frac, exp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module math | ||
|
||
fn C.log(x f64) f64 | ||
|
||
fn C.logf(x f32) f32 | ||
|
||
// log returns the natural logarithm of x (float64) | ||
[inline] | ||
pub fn log(a f64) f64 { | ||
return C.log(a) | ||
} | ||
|
||
// log returns the natural logarithm of x (float32) | ||
[inline] | ||
pub fn logf(a f32) f32 { | ||
return C.logf(a) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module math | ||
|
||
// square returns the square of the argument x, i.e. x * x | ||
[inline] | ||
pub fn square[T](x T) T { | ||
return x * x | ||
} | ||
|
||
// cube returns the cube of the argument x, i.e. x * x * x | ||
[inline] | ||
pub fn cube[T](x T) T { | ||
return x * x * x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import math | ||
|
||
fn test_square() { | ||
assert math.square(0) == 0 | ||
assert math.square(1) == 1 | ||
assert math.square(-1) == 1 | ||
assert math.square(5) == 25 | ||
assert math.square(u8(3)) == 9 | ||
assert math.square(u32(10)) == 100 | ||
assert math.square(-7) == 49 | ||
} | ||
|
||
fn test_cube() { | ||
assert math.cube(0) == 0 | ||
assert math.cube(1) == 1 | ||
assert math.cube(-1) == -1 | ||
assert math.cube(5) == 125 | ||
assert math.cube(u8(3)) == 27 | ||
assert math.cube(u32(10)) == 1000 | ||
assert math.cube(-7) == -343 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters