git.delta.rocks / jrsonnet / refs/commits / e70aa7db346b

difftreelog

Merge pull request #92 from CertainLach/fix-builtin-variable-names

Petr Portnov | PROgrm_JARvis2022-11-27parents: #a556594 #9b148f9.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-stdlib/src/math.rsdiffbeforeafterboth
1use jrsonnet_evaluator::{error::Result, function::builtin, typed::PositiveF64};1use jrsonnet_evaluator::{error::Result, function::builtin, typed::PositiveF64};
22
3#[builtin]3#[builtin]
4pub fn builtin_abs(x: f64) -> Result<f64> {4pub fn builtin_abs(n: f64) -> Result<f64> {
5 Ok(x.abs())5 Ok(n.abs())
6}6}
77
8#[builtin]8#[builtin]
9pub fn builtin_sign(x: f64) -> Result<f64> {9pub fn builtin_sign(n: f64) -> Result<f64> {
10 Ok(if x == 0. { 0. } else { x.signum() })10 Ok(if n == 0. { 0. } else { n.signum() })
11}11}
1212
13#[builtin]13#[builtin]
14pub fn builtin_max(x: f64, y: f64) -> Result<f64> {14pub fn builtin_max(a: f64, b: f64) -> Result<f64> {
15 Ok(x.max(y))15 Ok(a.max(b))
16}16}
1717
18#[builtin]18#[builtin]
19pub fn builtin_min(x: f64, y: f64) -> Result<f64> {19pub fn builtin_min(a: f64, b: f64) -> Result<f64> {
20 Ok(x.min(y))20 Ok(a.min(b))
21}21}
2222
23#[builtin]23#[builtin]
modifiedcrates/jrsonnet-stdlib/src/strings.rsdiffbeforeafterboth
76}76}
7777
78#[builtin]78#[builtin]
79pub fn builtin_parse_int(raw: IStr) -> Result<f64> {79pub fn builtin_parse_int(str: IStr) -> Result<f64> {
80 if let Some(raw) = raw.strip_prefix('-') {80 if let Some(raw) = str.strip_prefix('-') {
81 if raw.is_empty() {81 if raw.is_empty() {
82 throw!("integer only consists of a minus")82 throw!("integer only consists of a minus")
83 }83 }
8484
85 parse_nat::<10>(raw).map(|value| -value)85 parse_nat::<10>(raw).map(|value| -value)
86 } else {86 } else {
87 if raw.is_empty() {87 if str.is_empty() {
88 throw!("empty integer")88 throw!("empty integer")
89 }89 }
9090
91 parse_nat::<10>(raw.as_str())91 parse_nat::<10>(str.as_str())
92 }92 }
93}93}
9494
95#[builtin]95#[builtin]
96pub fn builtin_parse_octal(raw: IStr) -> Result<f64> {96pub fn builtin_parse_octal(str: IStr) -> Result<f64> {
97 if raw.is_empty() {97 if str.is_empty() {
98 throw!("empty octal integer");98 throw!("empty octal integer");
99 }99 }
100100
101 parse_nat::<8>(raw.as_str())101 parse_nat::<8>(str.as_str())
102}102}
103103
104#[builtin]104#[builtin]
105pub fn builtin_parse_hex(raw: IStr) -> Result<f64> {105pub fn builtin_parse_hex(str: IStr) -> Result<f64> {
106 if raw.is_empty() {106 if str.is_empty() {
107 throw!("empty hexadecimal integer");107 throw!("empty hexadecimal integer");
108 }108 }
109109
110 parse_nat::<16>(raw.as_str())110 parse_nat::<16>(str.as_str())
111}111}
112112
113fn parse_nat<const BASE: u32>(raw: &str) -> Result<f64> {113fn parse_nat<const BASE: u32>(raw: &str) -> Result<f64> {