Skip to content

Commit

Permalink
use Number.MIN_VALUE
Browse files Browse the repository at this point in the history
  • Loading branch information
drmibell committed Jan 6, 2022
1 parent dcea9d6 commit 7bc9a0a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions event.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ module.exports = function(RED) {
let outputPayload = node.outputPayload
let outputPayloadType = node.outputPayloadType
let payload = RED.util.evaluateNodeProperty(outputPayload, outputPayloadType, node)
let msgToSend = {"count":-1} // debug
let msgToSend = {"count":-1}
let maxEventCount = node.maxEventCount
if (maxEventCount <= 0) {maxEventCount = Infinity}
let state = 'stopped'
context.set('state',state)
let stoppedStatus = {fill:'red',shape:'ring',text:'stopped'} // debug
node.status(stoppedStatus) // debug
let stoppedStatus = {fill:'red',shape:'ring',text:'stopped'}
node.status(stoppedStatus)
let timer, delay

node.on('input', function(msg) {
Expand All @@ -66,7 +66,7 @@ module.exports = function(RED) {
}
break
case node.stopCmd:
if (state === 'stopped') { // already stopped
if (state === 'stopped') { // already stopped
node.warn('command ignored: already stopped')
return
}
Expand All @@ -80,7 +80,6 @@ module.exports = function(RED) {
}
}
context.set('state',state)
// node.warn(distribution) // debug
if (distribution === 'uniform' && min >= max) {
node.warn('must have max > min for uniform distribution')
return
Expand Down Expand Up @@ -133,25 +132,25 @@ module.exports = function(RED) {
if (msgToSend.count >= maxEventCount) {
state = 'stopped'
context.set('state',state)
node.status(stoppedStatus) // debug
node.status(stoppedStatus)
return
}
timer = setTimeout(loop,1000 * delay)
node.status({fill:'green',shape:'dot',text:delay.toFixed(2)})
}
}

function expInterval(m) { // see Knuth, Vol. 2, p. 133
function expInterval(m) { // see Knuth, Vol. 2, p. 133
let u = Math.random()
if (u === 0) {u = 5e-234}
if (u === 0) {u = Number.MIN_VALUE}
return - m * Math.log(u)
}

function uniformInterval(min,max) {
return Math.random() * (max - min) + min
}

function gaussianInterval(mu,sigma) { // Box–Muller method, see Knuth, Vol. 2, p. 122
function gaussianInterval(mu,sigma) { // Box–Muller method, see Knuth, Vol. 2, p. 122
let two_pi = 2 * Math.PI
let r, z0, z1, u1, u2
do {
Expand Down

0 comments on commit 7bc9a0a

Please sign in to comment.