パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.0.0

adaptive_number

適応的な数値実装を提供するライブラリです。JSランタイムでは、64ビット符号付き固定幅整数が使用され、他のすべてのプラットフォームでは、デフォルトのDart intデータ型が使用されます。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
70.2万
いいね数
2
Pub ポイント
150

パッケージをインストール

flutter pub add adaptive_number

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

adaptive_number パッケージは、実行時環境に応じて自動的に調整される数値型を提供します。JavaScript プラットフォームでは、一貫した精度を確保するために 64 ビット符号付き固定幅整数を使用し、その他のすべてのプラットフォームでは Dart のネイティブな int をデフォルトで使用します。これにより、Web とネイティブ環境間で信頼性の高い動作が保証され、特に大きな整数を扱う場合や、数値演算におけるクロスプラットフォームの一貫性が必要な場合に役立ちます。

用途

  • クロスプラットフォーム整数処理
  • 大量のウェブベースアプリケーション
  • プラットフォーム間での一貫した算術
  • 整数を含むデータのシリアライゼーション
  • Flutter Web アプリにおける数値計算

主な機能

  • プラットフォームに応じた適応的な整数サイズ
  • JS 上の64ビット固定幅整数
  • 非-JS プラットフォームにおけるネイティブ int のフォールバック
  • ランタイム間での一貫した振る舞い
  • 既存コードとの簡単な統合

適している対象

  • Webおよびネイティブプラットフォームをターゲットとする開発者
  • 正確な整数演算を必要とするアプリ
  • 数値論理のポータビリティが必要なプロジェクト
  • JS 固有の数値制限を回避するチーム
  • 共有ビジネスロジックを備えた Flutter アプリ

注意事項

  • 整数値のみに制限されています
  • 浮動小数点数のサポートなし
  • 非-JS プラットフォーム上のパフォーマンスオーバーヘッド
  • シンプルな使用例では必要ない可能性があります
  • JSターゲットでの慎重なテストが必要です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

adaptive_number

pub package Language Build codecov

A library providing a Number implementation that is dependent on the platform it is compiled for. For JS runtimes, the implementation uses a 64-bit signed fixed-width integer, for all other platforms the default Dart int data type.

Use cases of this library

The Number substitute is useful in situations where a value may overflow on JS runtimes since the available value range is not the same compared to mobile or desktop platforms:

https://api.dart.dev/stable/2.8.4/dart-core/int-class.html

The overflow on JS environments can be circumvented by using a BigInt or the fixed-with implementation of this library: https://pub.dev/packages/fixnum

The disadvantage of just replacing all usages of int with BigInt or fixnum/Int64 is that the performance on mobile platforms may suffer significantly.

The adpative_number library takes a conditional import approach to ease this problem:

  • If it runs on a JS runtime, Number wraps a fixnum/Int64
  • For all other platforms Number wraps a default Dart int type.

Some historical background of this library can also be seen in: https://github.com/MixinNetwork/libsignal_protocol_dart/pull/43

Usage

A Number instance is created by wrapping it around a default int value:

import 'package:adaptive_number/adaptive_number.dart';

void main() {
  final number1 = Number(93432);
  final number2 = Number(42435);
  assert((number1 + number2) == Number(51777));
}

All other operations on Number behave the same way as with int.

Features and bugs

Please file feature requests and bugs at the issue tracker.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト