Arithmetic operation resulted in an overflow

Arithmetic operation resulted in an overflow

aasemmahmoud174
Explorer Explorer
231 Views
1 Reply
Message 1 of 2

Arithmetic operation resulted in an overflow

aasemmahmoud174
Explorer
Explorer

I'm trying to tagging elements in revit api and for that i have to group nearby tags to for alignment by this script below.but I've arithmetic operation resulted in an overflow error and I've tried but unfortunately I didn't know what is wrong.
Can anybody help in this problem?

1.png

2.png

IMG-20221015-WA0048.jpg

0 Likes
232 Views
1 Reply
Reply (1)
Message 2 of 2

RPTHOMAS108
Mentor
Mentor

You are casting from double to integer (not enough capacity).

 

Integer is 32 bit double is 64 bit.

 

You could perhaps use Int64 but probably better to convert to a unit system where you can retain similar accuracy required but only use the integer portion of the double. e.g. Int32 can represent over 7 million feet to the nearest mm I believe (and that's just the positive portion). You are unlikely to need anything near that.

 

You may also check you C# overflow checking options, strange that you encounter it by default, but I've never attempted casting a double to an integer in C#.

 

The good and the bad thing about dictionaries is that they require unique keys. Keys should also have an equality function to distinguish them.