Hello Dears!

Is it possible to work with big numbers like 256 bit unsigned integers in Motoko?

Hello Dears!

Is it possible to work with big numbers like 256 bit unsigned integers in Motoko?

`Nat`

will represent numbers that large, but it’s not specific to a certain bit width.

When you say “working with”, what operations do you need?

Nat is described here (partly): Nat :: Internet Computer

I mean multiplication of two numbers like this one 123456789123456789 * 123456789123456789

when I did this then it produces “lost precision” error

Strange. I just tried the same multiplication in the Motoko repl and got this (no error):

```
Motoko compiler 0.6.5 (source ac3psafn-rp9bj68x-67s21qfv-z7fygv81)
> 123456789123456789 * 123456789123456789
;;
15_241_578_780_673_678_515_622_620_750_190_521 : Nat
>
```

You get that error from the Motoko compiler, during compile time?

1 Like

Oh sorry, it works for me also. But the actual problem is causes from conversion more than 64bit number to Float. Now actual question is: **Is there any way to get square root of numbers bigger than 64 bits?**

Here the code:

```
var num = 112345678912345678900 * 112345678912345678900; // OK
var ftval = Float.fromInt(num); // <- error
var sqr = Float.sqrt(ftval);
```

`canister trapped explicitly: losing precision`

1 Like

I opened new topic for this question

1 Like

Oh, hey if youre still here, I think Floating point numbers only have like x number of decimal precisioin for any language. If you want to use super big numbers you have to use massive ints but consider the last x number as “decimal” digits

1 Like