#Any fix for this without using static? I don't know if Im just doing the data types wrong

1 messages · Page 1 of 1 (latest)

raw spear
native steepleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

raw spear
kind reef
#

27000000000000000000 is way bigger than the max limit of uint64_t

#

Can you describe what exactly you're trying to do?

raw spear
#

I wanted to mulitply these two numbers together

#

So I made a multiply function however it seems to not work due to my data types. I only wanted the output to be a long double but I get an error if I don't also make those numbers above long doubles too

obtuse leaf
#

unsigned long long multiplied with unsigned long long gives unsigned long long.

raw spear
#

Understood. So have to keep everything same types for multiplication

obtuse leaf
#

Not really, the result type is determined based on the operands' types and not the variable in which the result is stored.

raw spear
#

isn't it still possible to have different operand types and still multiply them for the corrected value like in my case

obtuse leaf
#

When operands are of different types they are converted to one common type based on a few rules.

#

But what you are having is not.

#

Your result variable's type is different but the two operand types are the same.

raw spear
#

Ok thank you so static is the kinda the other only option

native steepleBOT
#

@raw spear Has your question been resolved? If so, type !solved :)

obtuse leaf
#

Wot, how is static related to this?

grave dagger
#

you could do result = static_cast<double>(large_number) * even_larger_number;
to force the result into a double, but double is not 'large' enough to store all the digits

I get the feeling this is a homework where one has to write a custom multiplication that can take very large numbers.
possibly as strings of digits

shrewd gate
#

;cpp << std::setprecision(1000000000) << 27000000000000000001.L;

odd ledgeBOT
#
Program Output
27000000000000000000
shrewd gate
# odd ledge

For example, you can see here that the last 1 is truncated from the output as it can't be represented by a 80bit float (which is used on godbolt, and most other machines

#

Also, you might want to check out GMP

grave dagger
grave dagger
shrewd gate
grave dagger
#

let's only use even numbers then 99

raw spear
#

Understood thank you all!

#

!solved

native steepleBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity