本文整理汇总了TypeScript中underscore.isFinite函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isFinite函数的具体用法?TypeScript isFinite怎么用?TypeScript isFinite使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isFinite函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _validateSequenceNumber
private _validateSequenceNumber(sequenceNumber: number) {
// checking that sequenceNumber is increasing
assert(_.isFinite(this._previousSequenceNumber));
assert(_.isFinite(sequenceNumber) && sequenceNumber >= 0);
let expectedSequenceNumber;
if (this._previousSequenceNumber !== -1) {
expectedSequenceNumber = this._previousSequenceNumber + 1;
if (expectedSequenceNumber !== sequenceNumber) {
const errMessage = "Invalid Sequence Number found ( expected " + expectedSequenceNumber + ", got " + sequenceNumber + ")";
/* istanbul ignore next */
debugLog(chalk.red.bold(errMessage));
/**
* notify the observers that a message with an invalid sequence number has been received.
* @event invalid_sequence_number
* @param expected sequence Number
* @param actual sequence Number
*/
this.emit("invalid_sequence_number", expectedSequenceNumber, sequenceNumber);
}
// todo : handle the case where sequenceNumber wraps back to < 1024
}
/* istanbul ignore next */
if (doDebug) {
debugLog(chalk.yellow.bold(" Sequence Number = "), sequenceNumber);
}
this._previousSequenceNumber = sequenceNumber;
}
示例2: _differenceScalar
function _differenceScalar(
value1: NumberType,
value2: NumberType,
dataType: DataType,
absoluteDeadband: number
): boolean {
let diff;
if (dataType === DataType.UInt64 || dataType === DataType.Int64) {
if (!(value1 instanceof Array && value2 instanceof Array)) {
throw new Error("Invalid");
}
const h1 = value1[0]; // high
const h2 = value2[0];
if (h1 !== h2) {
diff = (h1 - h2) * 4294967295;
if (Math.abs(diff) > absoluteDeadband) {
return true;
}
}
diff = value1[1] - value2[1];
assert(_.isNumber(diff) && _.isFinite(diff));
return Math.abs(diff) > absoluteDeadband;
}
if (!(typeof value1 === "number" && typeof value2 === "number")) {
throw new Error("Invalid");
}
diff = value2 - value1;
assert(_.isNumber(diff) && _.isFinite(diff));
return Math.abs(diff) > absoluteDeadband;
}
示例3: difference
function difference(v1: Variant, v2: Variant, absoluteDeadBand: number): boolean {
assert(_.isFinite(absoluteDeadBand));
if (v1.arrayType === VariantArrayType.Array) {
if (v1.dataType !== v2.dataType) {
return true;
}
if (v1.value.length !== v2.value.length) {
return true;
}
const n = v1.value.length;
let i = 0;
for (i = 0; i < n; i++) {
if (_differenceScalar(v1.value[i], v2.value[i], v1.dataType, absoluteDeadBand)) {
return true;
}
}
return false;
} else {
assert(v1.arrayType === VariantArrayType.Scalar);
assert(v1.dataType === v2.dataType);
return _differenceScalar(v1.value, v2.value, v1.dataType, absoluteDeadBand);
}
}
示例4: _setStateBasedOnInputValue
public _setStateBasedOnInputValue(value: number) {
assert(_.isFinite(value));
let isActive = false;
let state = null;
const oldState = this.limitState.getCurrentState();
if (this.highHighLimit && this.getHighHighLimit() < value) {
state = "HighHigh";
isActive = true;
} else if (this.highLimit && this.getHighLimit() < value) {
state = "High";
isActive = true;
} else if (this.lowLowLimit && this.getLowLowLimit() > value) {
state = "LowLow";
isActive = true;
} else if (this.lowLimit && this.getLowLimit() > value) {
state = "Low";
isActive = true;
}
if (state !== oldState) {
this._signalNewCondition(state, isActive, value);
}
}
示例5: _send_HELLO_request
private _send_HELLO_request() {
if (doDebug) {
debugLog("entering _send_HELLO_request");
}
assert(this._socket);
assert(_.isFinite(this.protocolVersion));
assert(this.endpointUrl.length > 0, " expecting a valid endpoint url");
// Write a message to the socket as soon as the client is connected,
// the server will receive it as message from the client
const request = new HelloMessage({
endpointUrl: this.endpointUrl,
maxChunkCount: 0, // 0 - no limits
maxMessageSize: 0, // 0 - no limits
protocolVersion: this.protocolVersion,
receiveBufferSize: 1024 * 64 * 10,
sendBufferSize: 1024 * 64 * 10 // 8192 min,
});
const messageChunk = packTcpMessage("HEL", request);
this._write_chunk(messageChunk);
}
示例6: _setStateBasedOnInputValue
public _setStateBasedOnInputValue(value: number) {
const setpointValue = this.getSetpointValue();
if (setpointValue === null) {
throw new Error("Cannot access setpoint Value");
}
assert(_.isFinite(setpointValue), "expecting a valid setpoint value");
// call base class implementation
super._setStateBasedOnInputValue(value - setpointValue);
}
示例7: setValue
public setValue(value: string | number): void {
if (typeof (value) === "string") {
const index = this.getIndex(value);
assert(index >= 0, " invalid multi state value provided");
return this.setValue(index);
}
assert(_.isFinite(value));
return this.setValueFromSource(new Variant({ dataType: DataType.UInt32, value }));
}
示例8: _timedShelve_method
function _timedShelve_method(
inputArguments: VariantLike[],
context: SessionContext,
callback: any
) {
assert(inputArguments.length === 1);
const shelvingState = context.object as ShelvingStateMachine;
if (shelvingState.getCurrentState() !== "Unshelved") {
return callback(null, {
statusCode: StatusCodes.BadConditionAlreadyShelved
});
}
// checking duration ...
const alarmNode = shelvingState.parent;
// istanbul ignore next
if (!(alarmNode instanceof UAAlarmConditionBase)) {
return callback(null, {
statusCode: StatusCodes.BadNodeIdInvalid
});
}
const maxTimeShelved = alarmNode.getMaxTimeShelved();
assert(_.isFinite(maxTimeShelved));
assert(inputArguments[0].dataType === DataType.Double); // Duration
assert(inputArguments[0] instanceof Variant);
// xx console.log("inputArguments",inputArguments[0].toString());
const proposedDuration = inputArguments[0].value; // as double (milliseconds)
if (proposedDuration > maxTimeShelved) {
return callback(null, {
statusCode: StatusCodes.BadShelvingTimeOutOfRange
});
}
if (proposedDuration < 0) {
return callback(null, {
statusCode: StatusCodes.BadShelvingTimeOutOfRange
});
}
_clear_timer_if_any(shelvingState);
shelvingState.setState("TimedShelved");
_start_timer_for_automatic_unshelve(shelvingState, proposedDuration);
return callback(null, {
statusCode: StatusCodes.Good
});
}
示例9: writeUInt32
/**
* write a single 32 bit unsigned integer to the stream.
*
* @param value the value to write
*/
public writeUInt32(value: number): void {
if (performCheck) {assert(this.buffer.length >= this.length + 4, "not enough space in buffer"); }
if (performCheck) {assert(isFinite(value)); }
if (performCheck) {assert(value >= 0 && value <= MAXUINT32); }
this.buffer.writeUInt32LE(value, this.length);
this.length += 4;
/*
assert(this.buffer[this.length - 4] === value % 256);
assert(this.buffer[this.length - 3] === (value >>> 8) % 256);
assert(this.buffer[this.length - 2] === (value >>> 16) % 256);
assert(this.buffer[this.length - 1] === (value >>> 24) % 256);
*/
}
示例10: _setStateBasedOnInputValue
protected _setStateBasedOnInputValue(value: number): void {
assert(_.isFinite(value), "expecting a valid value here");
const alarm = this;
let isActive = false;
const states: any = {
highHigh: alarm.highHighState ? alarm.highHighState.getValue() : "unset",
high: alarm.highState ? alarm.highState.getValue() : "unset",
low: alarm.lowState ? alarm.lowState.getValue() : "unset",
lowLow: alarm.lowLowState ? alarm.lowLowState.getValue() : "unset"
};
let count = 0;
function ___p(
stateName: string,
func_value: () => boolean
) {
if (states[stateName] !== "unset") {
const val = func_value();
isActive = isActive || val;
if (states[stateName] !== val) {
states[stateName] = val;
count += 1;
}
}
}
___p("highHigh", () => {
return alarm.getHighHighLimit() < value;
});
___p("high", () => {
return alarm.getHighLimit() < value;
});
___p("low", () => {
return alarm.getLowLimit() > value;
});
___p("lowLow", () => {
return alarm.getLowLowLimit() > value;
});
if (count > 0) {
alarm._signalNewCondition(states, isActive, value);
}
}