Libc Floating point - # of digit precision

C and PASCAL (or any other high-level languages) in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12673
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Libc Floating point - # of digit precision

Postby wongck » Thu Jun 14, 2012 6:16 am

I noticed that the printf statement prints out float to 6 digits of decimal.
I make a #define FLT_DIG 7 in my source but the printf still printed out to 6 digits of decimal.
Is this the way to increase the number of precision for float in Mint ??
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: Libc Floating point - # of digit precision

Postby Nyh » Thu Jun 14, 2012 7:09 am

wongck wrote:I noticed that the printf statement prints out float to 6 digits of decimal.
I make a #define FLT_DIG 7 in my source but the printf still printed out to 6 digits of decimal.
Is this the way to increase the number of precision for float in Mint ??

The C standard says printf prints floats with 6 digits by default. With a precision modifier you can increase the number of digits:
printf("%.7f", x);
for 7 digits,
printf("%.9f", x);
for 9.

Hope this helps,

Hans Wessels

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12673
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Libc Floating point - # of digit precision

Postby wongck » Thu Jun 14, 2012 2:51 pm

Well, I was asking how to increase the precision, not only printing the result out.
10.0/3.0 gives 3.3333332539 using float.

However I need up to 7 digit precision for my program.
So now I just use double instead which gives up to 15 digits precision.

Thanks for answering !!
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

Ato
Captain Atari
Captain Atari
Posts: 300
Joined: Tue Aug 10, 2010 3:27 am
Location: Duisburg, Germany

Re: Libc Floating point - # of digit precision

Postby Ato » Thu Aug 30, 2012 8:04 pm

wongck wrote:So now I just use double instead which gives up to 15 digits precision.


That's exactly the way how precision can be improved. printf just prints out what is already there, it cannot trigger a calculation with a better precision when a modifier would require it. And if double is not sufficient either, try long double - although, I am not sure if any compiler on the ST series supports this type.

Cheers,
T.

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 791
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Libc Floating point - # of digit precision

Postby mfro » Thu Aug 30, 2012 8:14 pm

you can always use the gmp library together with a gnu C compiler. Gives you arbitrary precision numbers. But don't expect a program using it to run fast on an Atari...

Ato
Captain Atari
Captain Atari
Posts: 300
Joined: Tue Aug 10, 2010 3:27 am
Location: Duisburg, Germany

Re: Libc Floating point - # of digit precision

Postby Ato » Thu Aug 30, 2012 8:27 pm

mfro wrote:you can always use the gmp library together with a gnu C compiler.


Yep. The question is if the gmp library is available on MiNT at all.

Cheers,
T.

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12673
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Libc Floating point - # of digit precision

Postby wongck » Thu Aug 30, 2012 11:05 pm

Ato wrote:
mfro wrote:you can always use the gmp library together with a gnu C compiler.

Yep. The question is if the gmp library is available on MiNT at all.

Lucky us... yes it is. :D
But I don't need that now, standard double works fine fornow on my PH Gmap program. :P
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 791
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Libc Floating point - # of digit precision

Postby mfro » Fri Aug 31, 2012 5:13 am

Ato wrote:
mfro wrote:you can always use the gmp library together with a gnu C compiler.


Yep. The question is if the gmp library is available on MiNT at all.

Cheers,
T.


It is. It's the foundation of gcc's soft-float functionality, so actually most programs generated by gcc already use it.


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 3 guests