Welcome! Log In Create A New Profile

Advanced

Another C++ Question

Posted by Arikado 
Another C++ Question
July 24, 2009 07:09PM
Is a long double the largest variable type that can hold a decimal number? Because it's sorta not big enough for what I'm writing... (Or at least not big enough when compiled with devkitPRO and ran on Wii)

Thanks in advance to all answers,
-Arikado



Edited 1 time(s). Last edit at 07/24/2009 07:19PM by Arikado.
Re: Another C++ Question
July 24, 2009 08:14PM
AFAIK, it is.

What are you trying to do, finding a good aproximation of Pi with the Wii?
Re: Another C++ Question
July 24, 2009 09:54PM
Well, long double goes crazy whenever its set to zero or less :/

Edit: Oh, and I'm cross developing a calculator application for dingoo dingux and Wii. Currently, everything works (and is ready for release for Wii) except decimal numbers...



Edited 2 time(s). Last edit at 07/24/2009 10:17PM by Arikado.
Re: Another C++ Question
July 25, 2009 09:13AM
What is a long double?
(a long, a double?)

Anyway, if you need a larger integer or floating point number, than the platform provides, then you need to implement it yourself.
Re: Another C++ Question
July 25, 2009 03:22PM
A double is larger than a float and can hold numbers with decimals. Thats all I know. AFAIK, It can't be set to anything that's 0 or less or it will freak out. (As will float)

The "long" keyword dictates that it will be able to hold greater values than a type without it.



Edited 1 time(s). Last edit at 07/25/2009 03:22PM by Arikado.
Re: Another C++ Question
July 25, 2009 04:28PM
In the meantime I did some reading.
In the x86 world, a long double seams to be the same as a double.
Maybe SSE or other extensions support a floating point type more precise than double.

PowerPC proccessors nativley support a 128 bit float. That would be a long double.
I do not know the bit pattern for it.

Quote
Arikado
AFAIK, It can't be set to anything that's 0 or less or it will freak out. (As will float)
Floats and doubles should be able to support negative numbers. The first bit indicates the sign.
Re: Another C++ Question
July 26, 2009 11:08AM
Quote
daniel_c_w
Floats and doubles should be able to support negative numbers. The first bit indicates the sign.
What about declaring it signed double? or signed long double?
Re: Another C++ Question
July 26, 2009 11:25AM
floats and doubles are always signed.
(the same should go long doubles)

floats: [en.wikipedia.org]
doubles: [en.wikipedia.org]
long doubles: [en.wikipedia.org]

The first bit indicates the sign.
The type can not be unsigned.

(in Visual C++ "unsigned double" leads to:
warning C4076: 'unsigned' : can not be used with type 'double')
Re: Another C++ Question
July 26, 2009 04:01PM
Yeah, you're completely right daniel_c_w. The problem therein lies then, that doubles/floats can't handle whole numbers and ints can't handle decimals... I'm shocked there isn't a variable storage type that can handle both.
Re: Another C++ Question
July 26, 2009 04:47PM
EDIT 2: I forgot about normalization, therefore most of the stuff down here is worng
(I shlashed through the wrong parts)


You should be able to handle whole numbers from (2 to the power of bits-for-fraction) down to - (2 to the power of bits-for-fraction).
For example:
Doubles use 52 bits for the fraction. Fraction is like an u52, an unsigned integer, that can hold all values from 0 to 2^52.
The sign is encoded seperately.
So all integers from -4503599627370496 to 4503599627370496 could be stored at full precison.

Keep in mind, that precision may be lost during all arithmetic operations with floats and doubles.
(oh and if you use floats, C and C++ will convert them to doubles everytime you use them in a function call)



Edited 3 time(s). Last edit at 07/28/2009 10:38PM by daniel_c_w.
Re: Another C++ Question
July 26, 2009 05:21PM
Quote
Arikado
Edit: Oh, and I'm cross developing a calculator application

For a calculator, you should definitly use a software implementation for fractions and big numbers.
You need precision
Re: Another C++ Question
July 27, 2009 07:25PM
Quote
daniel_c_w
Quote
Arikado
Edit: Oh, and I'm cross developing a calculator application

For a calculator, you should definitly use a software implementation for fractions and big numbers.
You need precision
Can you elaborate a bit please? Like what types of software should I implement?

I have a working calculator, and I have (what should be) a working algorithm to incorporate decimal numbers, I just can't use any C++ storage containers. If there's some software (like a small class) I can implement that can hold zero, whole numbers, decimal numbers, and return its member's stored values, please let me know.

Also, I've released what I have so far on my extra programs page here: [www.wiibrew.org]

Or you can read the latest blog post release here: [arikadosblog.blogspot.com]

EDIT: And by the way, for a calculator, the source is extremely small and simple.



Edited 2 time(s). Last edit at 07/27/2009 07:29PM by Arikado.
Re: Another C++ Question
July 27, 2009 08:35PM
[gmplib.org]
Perhaps useful to you, Arikado?
Re: Another C++ Question
July 27, 2009 09:23PM
Quote
PhoenixTank
http://gmplib.org/
Perhaps useful to you, Arikado?
Wow, looks great. I'll let you know if I can come up with anything. Thanks :-)
Re: Another C++ Question
July 28, 2009 08:35PM
For those who care:
I think I forgot, that floats get normalized.
I will try to create a fake precise float and see, if my (old) Athlon accepts it.


@PhoenixTank: thanks for the link, looks great.



Edited 1 time(s). Last edit at 07/28/2009 08:36PM by daniel_c_w.
Re: Another C++ Question
July 29, 2009 06:46AM
You're welcome, guys. I generally use BC Math with PHP, but couldn't find immediate source for that.
PHP can also use GMP for these situations, so I thought that might be useful here =)
Re: Another C++ Question
August 03, 2009 09:31PM
I believe I have to make GMP into a library before I use it, correct? If so, is there a special way I need to compile it to run under the Wii's processor?

(They don't have already compiled versions on their site anywhere do they?)



Edited 2 time(s). Last edit at 08/03/2009 09:33PM by Arikado.
Re: Another C++ Question
August 03, 2009 10:21PM
I would try to use the source code of all the fucntions you need.
Re: Another C++ Question
August 03, 2009 10:37PM
I did and I got an error (after linking what I thought was the main header) that "gmp.h" couldn't be found (and then megatons of errors afterwards as a result of that missing file). I couldn't find gmp.h anywhere in the download (I even used winrars find function and that failed).

Honestly, it's a little degrading that I wasn't able to get it to work after spending about a half hour with it :-P



Edited 1 time(s). Last edit at 08/03/2009 10:39PM by Arikado.
Re: Another C++ Question
September 11, 2009 01:29AM
Alright, I really want to get back into this project.

Unfortunately, I'm not having any luck with GMP.

Does anyone know of any other small, platform independent libraries which can help me out?
Sorry, only registered users may post in this forum.

Click here to login