How to get the maxium value of an Integer in dart? - dart

In java we can just Integer.maxValue but dart there is not this method.
I am using int max = 1<<32 but this doesn't work properly when compiling to javascript.
What is the best way to get the integer maximum value using dart language?

I was using dart_numerics package in my app for another reason and found it while typing

There is no method because the int maximum values are fixed.
According to the documentation:
Integers While the language specifies an arbitrarily sized integer,
for performance reasons the VM has three different internal integer
representations: smi (rhymes with pie), mint, and bigint. Each
representation is used to hold different ranges of integer numbers
(see the table). The VM automatically switches between these
representations behind the scenes as numbers grow and shrink in range.
You can read about that here: https://dart.dev/articles/archive/numeric-computation

Related

Delphi - comparison of two "Real" number variables

I have problem with comparison of two variables of "Real" type. One is a result of mathematical operation, stored in a dataset, second one is a value of an edit field in a form, converted by StrToFloat and stored to "Real" variable. The problem is this:
As you can see, the program is trying to tell me, that 121,97 is not equal to 121,97... I have read
this topic, and I am not copletely sure, that it is the same problem. If it was, wouldn't be both the numbers stored in the variables as an exactly same closest representable number, which for 121.97 is 121.96999 99999 99998 86313 16227 83839 70260 62011 71875 ?
Now let's say that they are not stored as the same closest representable number. How do I find how exactly are they stored? When I look in the "CPU" debugging window, I am completely lost. I see the adresses, where those values should be, but nothing even similar to some binary, hexadecimal or whatever representation of the actual number... I admit, that advanced debugging is unknown universe to me...
Edit:
those two values really are slightly different.
OK, I don't need to understand everything. Although I am not dealing with money, there will be maximum 3 decimal places, so "currency" is the way out
BTW: The calculation is:
DATA[i].Meta.UnUsedAmount := DATA[i].AMOUNT - ObjQuery.FieldByName('USED').AsFloat;
In this case it is 3695 - 3573.03
For reasons unknown, you cannot view a float value (single/double or real48) as hexadecimal in the watch list.
However, you can still view the hexadecimal representation by viewing it as a memory dump.
Here's how:
Add the variable to the watch list.
Right click on the watch -> Edit Watch...
View it as memory dump
Now you can compare the two values in the debugger.
Never use floats for monetary amounts
You do know of course that you should not use floats to count money.
You'll get into all sorts of trouble with rounding and comparisons will not work the way you want them too.
If you want to work with money use the currency type instead. It does not have these problems, supports 4 decimal places and can be compared using the = operator with no rounding issues.
In your database you use the money or currency datatype.

What is the max value of integer in dart?

I have looked everywhere but I couldnt find any information related to this topic.
Also, Is there a java - like Long / BigDecimal datatype in dart?
That depends if you are running in the Dart VM or compiling to JavaScript.
On the Dart VM an int is arbitrary precision and has no limit.
When compiling to JavaScript you are actually using floating point numbers, since that is all that JavaScript supports. This means you are restricted to representing integers within the range -253 to 253
Dart 2
For dart2js generated JavaScript Pixel Elephants answer is still true.
within the range -253 to 253
Other execution platforms have fixed-size integers with 64 bits.
The type BigInt was added to typed_data
Since Dart 2.0 will switch to fixed-size integers, we also added a BigInt class to the typed_data library. Developers targeting dart2js can use this class as well. The BigInt class is not implementing num, and is completely independent of the num hierarchy.
Dart 1
There are also the packages
- https://pub.dartlang.org/packages/bignum
- https://pub.dartlang.org/packages/decimal
I prefer this one:
int hugeInteger = double.maxFinite.toInt()

Lua Virtual Machine Register size

In the register based lua virtual machine are the registers fixed size?
Or is it a dynamic structure?
I found an bytecode example here at page 17 where the constant string "hello" is loaded into a register, so it must be dynamic? Isn't this uncommon for registers?
http://luaforge.net/docman/83/98/ANoFrillsIntroToLua51VMInstructions.pdf
Each register contains a Lua value. Lua values are implemented in C as tagged unions. See also: The Implementation Of Lua 5.0. This tagged union stores small types (booleans, numbers) by value and everything else (strings, tables, functions, etc.) as a pointer. So the size of a register is constant, though larger than one native machine word.

Bit-vector value in decimal

Using C++ APIs, how can you extract the decimal value of a bit-vector constant from a model.
There are several C-Functions that allow you to extract different types of values, depending on the expected size of the numerals: Z3_get_numeral_int, Z3_get_numeral_uint, Z3_get_numeral_uint64, Z3_get_numeral_int64. For numbers that don't fit into those basic types, we can use the Z3_get_numeral_string function to get a string representation that can be parsed into your preferred big-int representation.
Note that these functions are C-functions, not C++ functions, but those two APIs mix nicely. (See e.g, also z3 C++ API & ite).

Lua floating point operations

I run Lua on a CPU without dedicated floating point HW, depending on SW emulation.
From luaopt.h I can see that some macros are set to double, but it does not clearly state when floats are used and its a little hard to track it.
If my script does simple stuff like:
a=0
a=a+1
for...
Would that involve a floating point operations at any level?
If no that's fine, but what is then the benefit to change macros to long?
(I tried of course but did not work....)
All numeric operations in Lua are performed (according to the default configuration) in floating point. There is no distinction made between floating point and integer, all values are simply numbers.
The actual C type used to store a Lua number is set in luaconf.h, and it is both allowed and even practical to change that to a suitable integral type. You start by changing LUA_NUMBER from double to int, long, or perhaps ptrdiff_t. Then you will find you need to tweak the related macros that control the conversions between strings and numbers. And, of course, you will likely need to eliminate most or all of the base math library since math.sin() and its friends and neighbors are not particularly useful over integers.
The result will be a Lua interpreter where all numbers are integers. The language will still allow you to type 3.14, but it will be stored as 3. Your code will likely not be completely portable to a Lua interpreter built with the standard configuration since a huge amount of Lua code casually assumes that floating point arithmetic is permitted, and remember that your compiled byte code will definitely not be compatible since byte code will store numbers as LUA_NUMBER.
There is LNUM patch (used, for example, by OpenWrt project which relies heavily on Lua for providing Web UI on hardware without FPU) that allows dual integer/floating point representation of numbers in Lua with conversions happening behind the scenes when required. With it most integer computations will be performed without resorting to FPU. Unfortunately, it's only applicable to Lua 5.1; 5.2 is not supported.

Resources