Skip to content

Commit

Permalink
Merge branch 'main' into devops1
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor committed Apr 6, 2024
2 parents f937891 + f12e45d commit 67482ee
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CODE OF CONDUCT

1. Be nice and respectfull to others
2. Try to add value with your activity
3. Criticism is perfectly OK, but be constructive and respect points 1. and 2.
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Contributing

## Before PR-s
* Open and issue so we can make a discussion first

## Making PR-s
* Main branch shouldn't be left in a failed state (the red cross)
* PRs that are meant for merging should also pass all checks
* Each new builtin should have a docstring written and at least few tests
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ Rye's focus is also interactive use. Check out these asciinema demos:

Python is the *lingua franca* of dynamic programming languages, so comparing examples in Python and Rye can be helpful to some:

* [Less variables, more flows example vs Python](https://ryelang.blogspot.com/2021/11/less-variables-more-flows-example-vs.html)
* [Simple compression puzzle - from Python to Rye solution](https://github.com/otobrglez/compression-puzzle/blob/master/src/rye/compress_jm_rec_steps.rye)

## Modules
Expand Down
40 changes: 40 additions & 0 deletions evaldo/builtins_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,46 @@ var Builtins_math = map[string]*env.Builtin{
}
},
},
"acos": {
Argsn: 1,
Doc: "Returns the arccosine.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch val := arg0.(type) {
case env.Integer:
if val.Value < -1.0 || val.Value > 1.0 {
return MakeBuiltinError(ps, "Invalid input: Acos is only defined for -1 <= x <= 1.", "acos")
}
return *env.NewDecimal(math.Acos(float64(val.Value)))
case env.Decimal:
if val.Value < -1.0 || val.Value > 1.0 {
return MakeBuiltinError(ps, "Invalid input: Acos is only defined for -1 <= x <= 1.", "acos")
}
return *env.NewDecimal(math.Acos(val.Value))
default:
return MakeArgError(ps, 2, []env.Type{env.IntegerType, env.DecimalType}, "acos")
}
},
},
"acosh": {
Argsn: 1,
Doc: "Returns the inverse hyperbolic cosine.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch val := arg0.(type) {
case env.Integer:
if val.Value < 1.0 {
return MakeBuiltinError(ps, " Acosh is only defined for x >= 1.", "acosh")
}
return *env.NewDecimal(math.Log(float64(val.Value) + math.Sqrt(float64(val.Value)*float64(val.Value)-1)))
case env.Decimal:
if val.Value < 1.0 {
return MakeBuiltinError(ps, " Acosh is only defined for x >= 1.", "acosh")
}
return *env.NewDecimal(math.Log(val.Value + math.Sqrt(val.Value*val.Value-1)))
default:
return MakeArgError(ps, 2, []env.Type{env.IntegerType, env.DecimalType}, "acosh")
}
},
},
"pi": {
Argsn: 0,
Doc: "Return Pi constant.",
Expand Down
3 changes: 2 additions & 1 deletion tests/basics.rye
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ section "Printing functions"
stdout { printv 33 "value is: {}" } "value is: 33" + newline
; stdout { print\val "OK" "value is: {{}}" } "value is: 33" + newline ; TODO-BUG quotes the string
; stdout { { "Jane Austen" } print\val "Hello {{}}!" } "value is: 33" + newline
}
;}

; group "print-ssv"
; mold\nowrap ?print-ssv
; { { function } }
Expand Down
17 changes: 17 additions & 0 deletions tests/misc.rye
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,23 @@ section "Math functions"
equal { do\in math { abs 99.0 } } 99.0
}

group "acos"
mold\nowrap ""
{ { string } }
{
equal { do\in math { acos -1 } } 3.141592653589793
equal { do\in math { acos 0.5 } } 1.0471975511965976
equal { do\in math { acos 1 } } 0.000000
}

group "acosh"
mold\nowrap ""
{ { string } }
{
equal { do\in math { acosh 1 } } 0.000000
equal { do\in math { acosh 2 } } 1.3169578969248166
}

; TODO add sin and cos ... need PI constant

}
Expand Down

0 comments on commit 67482ee

Please sign in to comment.