當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript underscore.isFinite函數代碼示例

本文整理匯總了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;
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:32,代碼來源:message_builder.ts

示例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;

}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:33,代碼來源:deadband_checker.ts

示例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);
    }
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:28,代碼來源:deadband_checker.ts

示例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);
        }
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:27,代碼來源:ua_exclusive_limit_alarm.ts

示例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);
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:26,代碼來源:client_tcp_transport.ts

示例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);
 }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:9,代碼來源:ua_non_exclusive_deviation_alarm.ts

示例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 }));
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:10,代碼來源:ua_multistate_discrete.ts

示例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
    });

}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:53,代碼來源:shelving_state_machine.ts

示例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);
       */
 }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:18,代碼來源:binaryStream.ts

示例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);
        }
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:51,代碼來源:ua_non_exclusive_limit_alarm.ts


注:本文中的underscore.isFinite函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。