# Error #6901: The decimal constant was too large when converting to an integer, and overflow occurred

**URL:** <https://fortran-lang.discourse.group/t/error-6901-the-decimal-constant-was-too-large-when-converting-to-an-integer-and-overflow-occurred/8409>\
**Category:** Uncategorized\
**Created:** [July 30, 2024, 12:44am UTC](https://fortran-lang.discourse.group/t/error-6901-the-decimal-constant-was-too-large-when-converting-to-an-integer-and-overflow-occurred/8409 "2024-07-30T00:44:53Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [July 30, 2024, 3:50am UTC](https://fortran-lang.discourse.group/t/error-6901-the-decimal-constant-was-too-large-when-converting-to-an-integer-and-overflow-occurred/8409/4 "2024-07-30T03:50:47Z")

</div>

Thank you so much @urbanjost ! So awesome! 💯

I have another small question. In that Matlab code there are things like

```auto
s^m

```

where both s and m are integers. For example s=6, m=63, so s^m=6^63=10^49 or so.  
Thing is Matlab have no problem calculating 6^63,

Now, in Fortran, here both s and m are not big intergers, they are at most 60, so I may casually define them as integer(4). However in this example, the result s^m=6^63 cannot be represented by integer(4), integer(8) perhaps even higher should be used. So if I define s and m as integer(4) I got wrong results for s^m.

How would you handle case like that?  
I mean, do you manually change

```auto
s**m

```

to

```auto
int(s,kind=8)**m

```

or

```auto
real(s,kind=8)**m

```

if you suspect that s\*\*m may overflow?

Many thanks!

PS.  
This is perhaps somehow similar with some other posts before

> [@Integer 4 or integer 8?](https://fortran-lang.discourse.group/t/integer-4-or-integer-8/3076/5):
>
> Sure if you add -ftrapv, signed overflow will cause exception. But w/o it, gfortran (ifort as well) produces code that silently ignores overflow giving bogus results. For ifort there seems to be no equivalent of -ftrapv. For other compilers I do not know.

> [@"real" type of a calculation with mixed precisions](https://fortran-lang.discourse.group/t/real-type-of-a-calculation-with-mixed-precisions/8395/1):
>
> The result of a calculation involving mixed real precisions should use the highest precision: program precisions use iso\_fortran env: only: sp =\> real32, dp =\> real64 implicit none real(sp) :: x = 1.23 real(dp) :: xx = 1.23\_dp print \*, "single \* single: x \* x = ", x\*x ! 1.51289999 print \*, "double \* double: xx \* xx = ", xx\*xx ! 1.5128999999999999 print \*, "single \* double: x \* xx = ", x\*xx ! 1.5129000234603882 end program precisions I expect the calculati…

> [@Bug? (large integers...)](https://fortran-lang.discourse.group/t/bug-large-integers/7086):
>
> integer :: x x = (2\*33333333333333333) print \*, x end program Calculated a (large) negative value (!) yet use 1 less “3” or one more “3” returns large positive integer…(?)

---

_[View the full topic](https://fortran-lang.discourse.group/t/error-6901-the-decimal-constant-was-too-large-when-converting-to-an-integer-and-overflow-occurred/8409)._
