鸿蒙5.0开发进阶:NDK开发-使用Node-API接口操作bigint类型值

三方库移植之NAPI开发[2]C/C++与JS的数据类型转 index.ets搭建开发环境Windows 开发环境的搭建Ubuntu 开发环境搭建Linux 与 Windows 之间的文件共享……构建子系统启动流程子系统分布式任务调度子系统分布式通信子系统驱动子系统…… 阅读详情

往期鸿蒙全套实战文章必看:


简介

BigInt是ArkTS中用于表示任意精度整数的数据类型,它能够处理比Number类型更大范围的整数值。通过Node-API提供的接口,可以在Node-API模块中创建、获取和操作BigInt类型值,从而实现与BigInt相关的功能扩展。

基本概念

在使用Node-API接口操作BigInt类型值时,需要理解以下基本概念:

  • BigInt类型: BigInt是ArkTS中的一种数据类型,用于表示任意精度的整数。与Number类型不同,BigInt类型可以精确表示非常大的整数,而不会丢失精度或溢出。
  • BigInt创建: 使用Node-API提供的接口,可以通过传递C的int64或uint64数据来创建对应的ArkTS BigInt。这使得在Node-API模块中可以方便地创建BigInt类型值。
  • BigInt操作: Node-API提供了多个接口用于操作BigInt类型值。通过这些接口,可以获取BigInt的数值,进行数值转换,以及执行常见的算术和位运算操作。

场景和功能介绍

接口描述
napi_create_bigint_int64用于创建64位带符号整数(int64)的BigInt对象的函数。
napi_create_bigint_uint64用于创建64位无符号整数(uint64)的BigInt对象的函数。
napi_create_bigint_words用于根据提供的64位无符号(uint64)字节数据创建BigInt对象的函数。
napi_get_value_bigint_int64用于从BigInt对象中获取64位带符号整数(int64)值的函数。
napi_get_value_bigint_uint64用于从BigInt对象中获取64位无符号整数(uint64)值的函数。
napi_get_value_bigint_words用于从BigInt对象中获取底层的64位无符号(uint64)字节数据。

使用示例

本文仅对接口对应C++及ArkTS相关代码进行展示。

napi_create_bigint_int64

这个函数用于在给定的Node-API环境中依据一个带有符号的64位整数创建一个ArkTS的BigInt对象。

cpp部分代码

#include "napi/native_api.h"

static napi_value CreateBigintInt64t(napi_env env, napi_callback_info info)
{
    // 声明int64_t的变量value
    int64_t value = -5555555555555555555;
    // 将value转化为napi_value类型返回
    napi_value returnValue = nullptr;
    napi_create_bigint_int64(env, value, &returnValue);
    return returnValue;
}

接口声明

// index.d.ts
export const createBigintInt64t: () => bigint;

ArkTS侧示例代码

import hilog from '@ohos.hilog'
import testNapi from 'libentry.so'

hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_int64: %{public}d', testNapi.createBigintInt64t());

napi_create_bigint_uint64

这个函数用于在给定的Node-API环境中依据一个无符号的64位整数创建一个ArkTS的BigInt对象。

cpp部分代码

#include "napi/native_api.h"

static napi_value CreateBigintUint64t(napi_env env, napi_callback_info info)
{
    // 声明uint64_t的变量value
    uint64_t value = 5555555555555555555;
    // 将value转化为napi_value类型返回
    napi_value returnValue = nullptr;
    napi_create_bigint_uint64(env, value, &returnValue);
    return returnValue;
}

接口声明

// index.d.ts
export const createBigintUint64t: () => bigint;

ArkTS侧示例代码

import hilog from '@ohos.hilog'
import testNapi from 'libentry.so'

hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_uint64: %{public}d', testNapi.createBigintUint64t());

napi_create_bigint_words

这个函数用于在给定的Node-API环境中由一系列无符号64位整数创建一个ArkTS的BigInt对象。

cpp部分代码

#include "napi/native_api.h"

static napi_value CreateBigintWords(napi_env env, napi_callback_info info)
{
    // 使用napi_create_bigint_words接口创建一个BigInt对象
    int signBit = 0;
    size_t wordCount = 3;
    uint64_t words[] = {12ULL, 34ULL, 56ULL};
    napi_value returnValue = nullptr;
    napi_status status = napi_create_bigint_words(env, signBit, wordCount, words, &returnValue);
    if (status != napi_ok) {
        napi_throw_error(env, nullptr, "napi_create_bigint_words fail");
        return nullptr;
    }
    return returnValue;
}

接口声明

// index.d.ts
export const createBigintWords: () => bigint | void;

ArkTS侧示例代码

import hilog from '@ohos.hilog'
import testNapi from 'libentry.so'
try {
  hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_words: %{public}d', testNapi.createBigintWords());
} catch (error) {
  hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message);
}

napi_get_value_bigint_int64

用于从传入的参数中提取64位整数的BigInt数据,以供后续处理。

cpp部分代码

#include "napi/native_api.h"

static napi_value GetValueBigintInt64t(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1] = {nullptr};
    napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    // 从传入的参数中提取64位整数的BigInt数据
    int64_t value = 0;
    bool lossLess = false;
    napi_status status = napi_get_value_bigint_int64(env, args[0], &value, &lossLess);
    // 判断从ArkTS侧获取bigint是否为无损转换,如果不是抛出异常
    if (!lossLess) {
        napi_throw_error(env, nullptr, "BigInt values have not been lossless converted");
        return nullptr;
    }
    // 如果接口调用成功正常调用则返回true给ArkTS侧
    napi_value returnValue = nullptr;
    napi_get_boolean(env, status == napi_ok, &returnValue);
    return returnValue;
}

接口声明

// index.d.ts
export const getValueBigintInt64t: (bigInt64: bigint) => boolean | void;

ArkTS侧示例代码

import hilog from '@ohos.hilog'
import testNapi from 'libentry.so'
let bigInt = BigInt(-5555555555555555);
try {
  hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_int64: %{public}s',
             JSON.stringify(testNapi.getValueBigintInt64t(bigInt)));
} catch (error) {
  hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message);
}

napi_get_value_bigint_uint64

用于从传入的参数中提取无符号64位整数的BigInt数据,以供后续处理。

cpp部分代码

#include "napi/native_api.h"

static napi_value GetValueBigintUint64t(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1] = {nullptr};
    napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    // 从参数值中获取BigInt的数值
    uint64_t value = 0;
    bool lossLess = false;
    napi_status status = napi_get_value_bigint_uint64(env, args[0], &value, &lossLess);
    // 判断从ArkTS侧获取bigint是否为无损转换,如果不是抛出异常
    if (!lossLess) {
        napi_throw_error(env, nullptr, "BigInt values have no lossless converted");
        return nullptr;
    }
    // 如果接口调用成功正常调用则返回true给ArkTS侧
    napi_value returnValue = nullptr;
    napi_get_boolean(env, status == napi_ok, &returnValue);
    return returnValue;
}

接口声明

// index.d.ts
export const getValueBigintUint64t: (bigUint64: bigint) => boolean | void;

ArkTS侧示例代码

import hilog from '@ohos.hilog'
import testNapi from 'libentry.so'
let bigUint = BigInt(5555555555555555);
try {
  hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_uint64: %{public}s',
             JSON.stringify(testNapi.getValueBigintUint64t(bigUint)));
} catch (error) {
  hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message);
}

napi_get_value_bigint_words

用于获取ArkTS的BigInt对象底层的64位无符号(uint64)二进制字节数据。

cpp部分代码

#include "hilog/log.h"
#include "napi/native_api.h"

static napi_value GetValueBigintWords(napi_env env, napi_callback_info info)
{
    size_t argc = 1;
    napi_value args[1] = {nullptr};
    napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
    int signBit = 0;
    size_t wordCount = 0;
    uint64_t words = 0;
    // 调用napi_get_value_bigint_words接口获取wordCount
    napi_status status = napi_get_value_bigint_words(env, args[0], nullptr, &wordCount, nullptr);
    OH_LOG_INFO(LOG_APP, "Node-API , wordCount:%{public}d.", wordCount);
    // 调用napi_get_value_bigint_words接口获取传入bigInt相关信息,如:signBit传入bigInt正负信息
    status = napi_get_value_bigint_words(env, args[0], &signBit, &wordCount, &words);
    OH_LOG_INFO(LOG_APP, "Node-API , signBit: %{public}d.", signBit);
    if (status != napi_ok) {
        OH_LOG_ERROR(LOG_APP, "Node-API , reason:%{public}d.", status);
        napi_throw_error(env, nullptr, "napi_get_date_value fail");
        return nullptr;
    }
    // 将符号位转化为int类型传出去
    napi_value returnValue = nullptr;
    napi_create_int32(env, signBit, &returnValue);
    return returnValue;
}

接口声明

// index.d.ts
export const getValueBigintWords: (bigIntWords: bigint) => bigint | void;

ArkTS侧示例代码

import hilog from '@ohos.hilog'
import testNapi from 'libentry.so'
let bigInt = BigInt(-5555555555555555);
let bigUint = BigInt(5555555555555555);
try {
  hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_words signBit is: %{public}d', testNapi.getValueBigintWords(bigInt));
  hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_words signBit is: %{public}d', testNapi.getValueBigintWords(bigUint));
} catch (error) {
  hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message);
}

以上代码如果要在native cpp中打印日志,需在CMakeLists.txt文件中添加以下配置信息(并添加头文件:#include "hilog/log.h"):

// CMakeLists.txt
add_definitions( "-DLOG_DOMAIN=0xd0d0" )
add_definitions( "-DLOG_TAG=\"testTag\"" )
target_link_libraries(entry PUBLIC libhilog_ndk.z.so)

一文了解HarmonyOS Next ArkTS与C++数据类型转换 本文介绍了C++与TS各自数据类型与互相之间的数据类型转换,在需要使用C++模块时可以快速上手对各种数据类型进行转换。 阅读详情

相关推荐

从零搭建企业网络:使用Packet Tracer模拟多区域OSPF组网全过程

本文通过Cisco Packet Tracer模拟,详细演示了从零搭建一个典型企业多区域OSPF网络的完整流程。内容涵盖网络拓扑规划、IP地址设计、多区域划分原理,并提供了从设备初始化、接口配置到OSPF多区域核心配置与验证的详细步骤。文章旨在帮助网络学习者与IT支持人员通过动手实验,将理论知识转化为实际的配置与排障能力。

day7的博客 1032

HarmonyOS开发:ArkTs常见数据类型(二)

日常的开发中最常用的数据类型有:number,boolean,string,object,enum,undefined,null,其他的数据类型大家作为一个简单的了解即可。

知足常乐 3822

COMSOL金属氢化物-放氢过程

"层流"的出口设置压降函数,解决“找不到一致的初始值”问题,主要是一开始设置出口为1atm的话,压力场过渡太剧烈,不好找到初始解,要么就先算个稳态流场,这种也能求解。注:P0是根据实测PCT的插值曲线(函数名称为:p_iso)得到的,根据初始质量储氢量wtw0,和初始温度条件T0,然后根据函数p_iso(wtw0)*exp(-deltHd/R_const*(1/T0-1/303.15[K]))求解获得。若"初始步长"选择框不勾上,前面0~5s内的求解容易发散,然后求解失败。2、设置"达西定律"的。

qq_24800941的博客 1932

HarmonyOS开发:ArkTs常见数据类型(一)

本文针对开发中常用的数据类型,做一个简单的概述,便于第一次接触到ArkTs语言开发的同学,能够快速的对数据类型做一个了解。

知足常乐 4045

第零章 序 Chisel教程汇总

笔者目前西安交通大学微电子硕士在读,研究方向为数字集成电路设计与体系结构。鉴于目前RISC-V的火热程度,笔者参与了课题组的RISC-V项目,并了解、学习了颇受关注的新型硬件构建语言——Chisel,当前参与的神经网络加速器设计便是使用Chisel开发的。这是一门敏捷开发语言,据称要比传统的Verilog语言快很多。在亲身使用过后,笔者发现确实快了不少。这主要得益于Scala作为高级语言的简洁风格...

qq_34291505的博客 7万+

置顶必读(1) | 2026最新首发,全网最全 Spring Boot 学习宝典(附思维导图)

从0到1以知识点+实例+项目的教学模式对SpringBoot框架由浅入深进行学习,快来跟bug菌一起学习吧。

**My Coding Family** 16万+

Java、Kotlin、Flutter、HarmonyOS基本数据类型

undefined表示一个变量尚未赋值或不存在的值。它是 TypeScript 的一个原始数据类型,用于表示缺少值的状态。如果想要成为架构师或想突破20~30K薪资范畴,那就不要局限在编码,业务,要会选型、扩展,提升编程思维。此外,良好的职业规划也很重要,学习的习惯很重要,但是最重要的还是要能持之以恒,任何不能坚持落实的计划都是空谈。

xiaokangss的博客 1349

突破Cloudflare 5秒盾!Python爬虫+GPT分析JS混淆实战(附完整代码)

这篇文章的核心观点其实不是“怎么过CF”,而是如何把LLM嵌入逆向工程的工作流。AI不会取代逆向工程师,但它正在重新定义逆向工程师的工作方式。过去我们80%的时间花在读懂混淆代码上,现在这部分可以外包给GPT,我们把精力集中在架构判断、异常处理和系统设计这些真正需要人类直觉的地方。技术会变,CF的防护会升级,GPT的能力也会迭代。但这种“人机协作拆解复杂问题”的方法论,比任何具体的绕过技巧都更有长期价值。参考资料Cloudflare Bot Management官方文档。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 544

ArKTs 数据类型

当你定义了一个变量而未赋值时,那么它就是undefined。let testlet test//用undefined 判断某个数据是否有值,if (test!console.log("有值")} else {console.log("无值")type sex = "男" | "女" | "未知";let zhangsan:sex = "男";类似枚举type sex = "男" | "女" | "未知";let zhangsan:sex = "男";

Cyx080811的博客 1111

【Bug已解决】Request timed out / API Timeout — Claude Code 请求超时解决方案

方案适用场景推荐指数难度方案一:增加超时大任务处理⭐⭐⭐⭐⭐低方案二:切换 SonnetOpus 太慢⭐⭐⭐⭐⭐低方案三:缩小范围大代码库⭐⭐⭐⭐⭐低方案四:优化网络网络延迟高⭐⭐⭐⭐中方案五:减少 MCPMCP 超时⭐⭐⭐中方案六:流式响应长生成任务⭐⭐⭐低根本原因:请求超时最常见原因是请求体过大(35%)和 Opus 模型推理慢(25%),默认 60 秒超时阈值对大型任务不够最佳实践。

一键难忘的博客 5165

【论文翻译】YOLO26: KEY ARCHITECTURAL ENHANCEMENTS AND PERFORMANCE BENCHMARKING FOR REAL-TIME OBJECT DETEC

本研究对Ultralytics YOLO26进行了全面分析,重点阐述了其在实时边缘目标检测领域的关键架构改进与性能基准测试结果。YOLO26于2025年9月发布,是YOLO系列中最新、最先进的模型,专为在边缘设备和低功耗设备上实现高效能、高精度和部署就绪性而设计。论文依次详细介绍了YOLO26的架构创新,包括移除分布焦点损失(DFL)、采用端到端无非极大值抑制(NMS)推理、集成渐进式损失(ProgLoss)和小目标感知标签分配(STAL),以及引入MuSGD优化器以实现稳定收敛。

Limiiiing的博客 1692

【每日学点鸿蒙知识】初始化BigInt、包体积瘦身、Tabs嵌套Grid、老年化适配、Release打包失败

应用存在多包(HAP、HSP)的场景时,可以使用HSP(Harmony Shared Package)动态共享包在应用的多个包(HAP、HSP)之间共享代码和资源,消除使用HAR(Harmony Archive)静态共享包造成的多包(HAP、HSP)间代码和资源的重复拷贝,从而减小应用包大小。在多包场景下,如果应用的多个HAP或HSP包使用HAR包实现代码和资源的共享,那么打包后的每个HAP或HSP包中都会存在一份共享HAR包的拷贝,导致App包中存在冗余代码和资源。同一包内有重复资源,删除重复资源。

轻口味的专栏 823

基于Jeecgboot3.9.0的flowable7.2.0流程增加一个OA请假单功能例子(二)

基于Jeecgboot3.9.0的flowable7.2.0流程增加一个OA请假单功能例子(二)

宁波阿成的博客 202

鸿蒙5.0开发进阶:NDK代码开发-Node-API使用指南(使用Node-API接口操作bigint类型值)

BigInt是ArkTS中用于表示任意精度整数的数据类型...........

Androidbye的博客 1132

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

鸿蒙5.0&next开发【使用Node-API接口操作bigint类型值】NDK开发

BigInt是ArkTS中用于表示任意精度整数的数据类型,它能够处理比Number类型更大范围的整数值。通过Node-API提供的接口,可以在Node-API模块中创建、获取和操作BigInt类型值,从而实现与BigInt相关的功能扩展。

bbq的博客 930

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

鸿蒙5.0&next开发【使用Node-API接口创建基本数据类型】NDK开发

ArkTS的Number类型是一个双精度64位二进制格式IEEE 754值。只有在-2^53+1到2^53-1范围内(闭区间)的整数才能在不丢失精度的情况下被表示,在超过该取值范围的情况下,需要使用BigInt对应的NPI接口来处理更大范围的整数。

bbq的博客 1073

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

鸿蒙BigInt使用

精度已丢失的number类型,转换成bigint类型不能恢复精度;但也不保留原来的number值。2、超范围BigInt类型转number会精度丢失;1、超范围数字字符串用BigInt处理无精度丢失;

m0_46177819的博客 180

鸿蒙NEXT版实战开发:如何获取对象的类名?

可以先获取类的实例,然后通过constructor的name属性获取类名。

qq_39652397的博客 388

鸿蒙5.0&next开发【使用JSVM-API接口操作bigint类型值】使用JSVM-API实现JS与C/C++语言交互

BigInt是JavaScript中用于表示任意精度整数的数据类型,它能够处理比Number类型更大范围的整数值。通过JSVM-API提供的接口,可以在JSVM模块中创建、获取和操作BigInt类型值,从而实现与BigInt相关的功能扩展。

bbq的博客 547

ArkTS中number类型在表示大整数时会造成精度丢失

【代码】AArkTS中number类型在表示大整数时会造成精度丢失。

beta___的博客 399

鸿蒙5.0开发【如何处理大整数】应用运维

BigInt可以表示任意大小的整数,使用BigInt时,需要在整数字面量后面添加n后缀或者使用BigInt()构造函数。

鸿蒙的技术博客 180

鸿蒙中 JSON库处理BigInt、浮点数

功能原生JSON扩展库严格参数校验不支持支持循环引用检测不支持支持BigInt处理不支持支持增强的错误处理(BusinessError)不支持支持额外方法(has/remove)不支持支持数据类型处理金融数据使用固定精度序列化大整数使用BigInt模式解析敏感数据在序列化前进行脱敏处理。

梦想不只是梦与想的博客 1915

鸿蒙仓颉语言【基础-数据类型dataType】

仓颉中常见的高级泛型有: Collection: 泛型集合类型 ArrayList:泛型数组链表类型 Array: 泛型数组类型 Result: 泛型结果类型,表示可能包含错误的结果。高级类型,非常多,多以标准库或者可扩展库提供,你也可以编写自己的类库,这里列举一些常见的高级类型。这些是一些可能的数据类型和示例,具体的Rust代码实现可能有所不同,这里只是提供了一个对比参考。需要注意语言规约是所有的数据类型名都是大写。或其他类型,Type可以是任意自定义类型,如。

鸿蒙的技术博客 894

跨语言的复杂参数类型传递

hongxiaomeng的博客 1990

【HarmonyOS NEXT】JSON.parse解析返回的数据json有误

这是由于JavaScript使用的IEEE 754标准双精度浮点数表示,它有53位的精度,JSON.parse函数在解析大整数时可能会出现超出了JavaScript的Number类型所能表示的范围,造成精度丧失,导致尾数变为0。json解析时,数据model定义的number取某字段的2308543339213693963,自行转换成了2308543339213694000。json / 解析 / 数据。

Mayism123的博客 1366

JSONObject使用方法

**参见API:E:\java学习笔记\JSON_NOTE\API** JSONObject介绍 JSONObject-lib包是一个beans,collections,maps,java arrays和xml和JSON互相转换的包。 下载jar包 http:...

chenshoumo1978的博客 1230
上一篇: 鸿蒙5.0开发进阶:NDK开发-使用Node-API接口进行ArrayBuffer相关开发
下一篇: 鸿蒙5.0开发进阶:NDK开发-使用Node-API接口进行buffer相关开发
懂你的大海
博客等级 码龄6年 9049粉丝 1381原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值