fix rng not being inclusive

coroutines
Ondřej Hruška 4 years ago
parent 506a4e42a2
commit 1cfab8d21e
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 76
      README.md
  2. 2
      crsn_arith/src/exec.rs
  3. 6
      examples/flipcoin.csn
  4. 8
      examples/frandom.csn

@ -557,92 +557,96 @@ Here's an abridged summary of the floating point submodule:
(most of these support the shorthand version too - `RW` in place of `Wr Rd`) (most of these support the shorthand version too - `RW` in place of `Wr Rd`)
``` ```
; IntToFloat ; Convert int to float
(itf Wr Rd) (itf Wr Rd)
; FloatToInt (round) ; Convert float to int (round)
(fti Wr Rd) (fti Wr Rd)
; FloatToInt (ceil) ; Convert float to int (ceil)
(ftic Wr Rd) (ftic Wr Rd)
; FloatToInt (floor) ; Convert float to int (floor)
(ftif Wr Rd) (ftif Wr Rd)
; FloatTest - nan->invalid, infinities->overflow, positive, negative, zero ; Test properties of a float
; Set flags:
; NaN -> invalid
; Infinities -> overflow
; Positive, negative, zero
(ftst Rd) (ftst Rd)
; FloatCompare ; Float compare
(fcmp Rd Rd) (fcmp Rd Rd)
; FloatRangeTest ; Float range test
(fcmpr Rd Rd'min Rd'max) (fcmpr Rd Rd'min Rd'max)
; FloatRng ; FloatRng. Unlike rng, frng is exclusive in the higher bound
(frng Wr Rd'min Rd'max) (frng Wr Rd'min Rd'max)
; --- Basic float arith --- ; --- Basic float arith ---
; FloatAdd ; Float add
(fadd Wr Rd Rd) (fadd Wr Rd Rd)
; FloatSub ; Float subtract
(fsub Wr Rd Rd) (fsub Wr Rd Rd)
; FloatMul ; Float multiply
(fmul Wr Rd Rd) (fmul Wr Rd Rd)
; FloatPow ; Float power
(fpow Wr Rd Rd'pow) (fpow Wr Rd Rd'pow)
; FloatRoot ; Float root
(froot Wr Rd Rd'root) (froot Wr Rd Rd'root)
; FloatHyp ; Float hyp - sqrt(a*a + b*b)
(fhyp Wr Rd Rd) (fhyp Wr Rd Rd)
; FloatDiv ; Float divide
(fdiv Wr Wr'rem Rd'a Rd'div) (fdiv Wr Wr'rem Rd'a Rd'div)
; FloatMod ; Float modulo
(fmod Wr Rd'a Rd'div) (fmod Wr Rd'a Rd'div)
; FloatAbs ; Float abs value
(fabs Wr Rd) (fabs Wr Rd)
; FloatSgn ; Float signum (returns -1 or 1)
(fsgn Wr Rd) (fsgn Wr Rd)
; --- Basic trig --- ; --- Basic trig ---
; FloatSin ; Float sine
(fsin Wr Rd) (fsin Wr Rd)
; FloatAsin ; Float arcsine
(fasin Wr Rd) (fasin Wr Rd)
; FloatCos ; Float cosine
(fcos Wr Rd) (fcos Wr Rd)
; FloatAcos ; Float arccosine
(facos Wr Rd) (facos Wr Rd)
; FloatTan ; Float tangent
(ftan Wr Rd) (ftan Wr Rd)
; FloatAtan ; Float arctangent
(fatan Wr Rd) (fatan Wr Rd)
; FloatAtan2 ; Float 2-argumenmt arctangent
(fatan2 Wr Rd'y Rd'x) (fatan2 Wr Rd'y Rd'x)
; FloatCot ; Float cotangent
(fcot Wr Rd) (fcot Wr Rd)
; FloatAcot ; Float arccotangent
(facot Wr Rd) (facot Wr Rd)
; --- Hyperbolic trig --- ; --- Hyperbolic trig ---
; FloatHypSin ; Float hyperbolic sine
(fsinh Wr Rd) (fsinh Wr Rd)
; FloatHypAsin ; Float hyperbolic arcsine
(fasinh Wr Rd) (fasinh Wr Rd)
; FloatHypCos ; Float hyperbolic cosine
(fcosh Wr Rd) (fcosh Wr Rd)
; FloatHypAcos ; Float hyperbolic arccosine
(facosh Wr Rd) (facosh Wr Rd)
; FloatHypTan ; Float hyperbolic tangent
(ftanh Wr Rd) (ftanh Wr Rd)
; FloatHypAtan ; Float hyperbolic arctangent
(fatanh Wr Rd) (fatanh Wr Rd)
; FloatHypCot ; Float hyperbolic cotangent
(fcoth Wr Rd) (fcoth Wr Rd)
; FloatHypAcot ; Float hyperbolic arccotangent
(facoth Wr Rd) (facoth Wr Rd)
``` ```
Wow, thats a lot. I didn't test many of these yet. There may be bugs. Wow, thats a lot. I didn't test many of these yet. There may be bugs.
There are also some pre-defined constants: `PI`, `PI_2`, `TAU`, `E` There are also some pre-defined constants: `PI`, `PI_2` (½×`PI`), `TAU` (2×`PI`), `E`
## Buffers Module ## Buffers Module

@ -84,7 +84,7 @@ impl OpTrait for ArithOp {
offset + if max == u64::MAX { offset + if max == u64::MAX {
rand::thread_rng().gen() rand::thread_rng().gen()
} else { } else {
rand::thread_rng().gen_range(0, max) rand::thread_rng().gen_range(0, max + 1)
} }
}; };
state.write(dst, val)?; state.write(dst, val)?;

@ -0,0 +1,6 @@
(
(ld r0 5)
(:next)
(rng r1 0 1 (z? (lds @cout "(1€)\n")) (else? (lds @cout "(::)\n")))
(dec r0 (nz? (j :next)))
)

@ -0,0 +1,8 @@
(
(:loop)
(frng r0 0.0 1.0)
(fcmp r0 1.0
(lt? (j :loop))
(eq? (lds @cout "OK"))
(gt? (lds @cout "OVER!")))
)
Loading…
Cancel
Save