Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
225 user(s) are online (126 user(s) are browsing Forums)

Members: 1
Guests: 224

nbache, more...

Headlines

 
  Register To Post  

(1) 2 »
Float display
Quite a regular
Quite a regular


See User information
I just realised that RawDoFmt() does not have a %f formating command. How are we supposed to deal with double and float ?

Back to a quiet home... At last
Go to top
Re: Float display
Just popping in
Just popping in


See User information
Standard C library I'm afraid... You can link with snprintf() in a shared library.

Go to top
Re: Float display
Quite a regular
Quite a regular


See User information
Quote:

centaurz wrote:
Standard C library I'm afraid... You can link with snprintf() in a shared library.


Hmm too bad I try not to mix C runtime calls and native calls :(
I don't understand what can block inclusion of %f and %g into RawDoFmt now

Back to a quiet home... At last
Go to top
Re: Float display
Just popping in
Just popping in


See User information
@abalaban

Quote:

I don't understand what can block inclusion of %f and %g into RawDoFmt now


Double floats alignment issues with 68k args arrays, I would say.

Go to top
Re: Float display
Quite a regular
Quite a regular


See User information
IExec->RawDoFmt() is an exec call installed for minimal I/O. It doesn't handle floating point variables [neither does its more modern replacement, IUtility->SNPrintf()].

Applications that want to output floating point are likely to use the C runtime library, so they can use printf().

cheers
tony
Go to top
Re: Float display
Quite a regular
Quite a regular


See User information
Quote:

tonyw wrote:
IExec->RawDoFmt() is an exec call installed for minimal I/O. It doesn't handle floating point variables [neither does its more modern replacement, IUtility->SNPrintf()].


In fact I noticed that using IUtility->SNPrintf()

Quote:
Applications that want to output floating point are likely to use the C runtime library, so they can use printf().


No my application wants to display frequencies in Hz with two fractional digits. Calculus is done using lib fftw3 which might (probably) use C runtime functions but my application is only trying to display this into a string gadget and don't use any C runtime functions until now.

Back to a quiet home... At last
Go to top
Re: Float display
Just can't stay away
Just can't stay away


See User information
@abalaban

Quote:

No my application wants to display frequencies in Hz with two fractional digits.


In that case you could just use some simple code like this:
float32 fFreq;
int32 iFreq;
TEXT buffer[16];
iFreq = (int32)roundf(fFreq 100.0);
IUtility->SNPrintf(buffersizeof(buffer), "%ld.%02ld"iFreq 100iFreq 100);


Go to top
Re: Float display
Quite a regular
Quite a regular


See User information
Quote:

salass00 wrote:
In that case you could just use some simple code like this:
float32 fFreq;
int32 iFreq;
TEXT buffer[16];
iFreq = (int32)roundf(fFreq 100.0);
IUtility->SNPrintf(buffersizeof(buffer), "%ld.%02ld"iFreq 100iFreq 100);



Yes that's what I'm going to do, but that's a bit sad to do that... Anyway that's not a big deal.

Back to a quiet home... At last
Go to top
Re: Float display
Quite a regular
Quite a regular


See User information
Why do you want to use IExec->RawDoFmt() ?
What's wrong with sprintf() ? At least it's portable.

cheers
tony
Go to top
Re: Float display
Quite a regular
Quite a regular


See User information
@Tonyw

*I* don't want to use IExec->RawDoFmt() but IUtility->SNPrintf() does

I have nothing against snprintf() and portability but I try to not mix ANSI and native calls in the same program.

Back to a quiet home... At last
Go to top
Re: Float display
Quite a regular
Quite a regular


See User information
OK, I'll ask the question a different way - why use IUtility->SNPrintf() at all, if it doesn't do what you want (floating point) ?

By "native" calls, I suppose you mean AOS-centric calls? Why restrict yourself to AOS-centric calls? Why not use the standard, built-in C library that's already there? No one is going to think less of you if you use built-in calls and external-library calls in the same module.

Maybe I'm missing the point, but I don't understand your reluctance to use the standard tools provided.

cheers
tony
Go to top
Re: Float display
Quite a regular
Quite a regular


See User information
Quote:

tonyw wrote:
OK, I'll ask the question a different way - why use IUtility->SNPrintf() at all, if it doesn't do what you want (floating point) ?


I didn't know SNPrintf was not doing what I wanted until I noticed it...

Quote:
By "native" calls, I suppose you mean AOS-centric calls? Why restrict yourself to AOS-centric calls? Why not use the standard, built-in C library that's already there? No one is going to think less of you if you use built-in calls and external-library calls in the same module.

Maybe I'm missing the point, but I don't understand your reluctance to use the standard tools provided.


There was a time when mixing DOS I/O calls with C runtime I/O calls wasn't a good idea since then I try to not mix them as safety measure.

Back to a quiet home... At last
Go to top
Re: Float display
Just popping in
Just popping in


See User information
And its still a good idea, because dos.library and C runtime still carry their very own contexts.

There is some kind of warranty that mixing up these contexts will do no harm to the system, but as context information is very scarce (still), there is some danger that a coder might mess up one or the other context, on e.g. program termination, by accident (e.g. Exit() instead of exit() for an "emergency shutdown" and some other cases still not cleared).

Edit: Forgot something Portability in mind is always a nice idea, but for AmigaOS only programs its quite useless to keep "portability" by using C runtime libraries. A program wont get portable magically by using C runtime calls only.

It depends on the intentions of the developer, if a program is "portable" by design or not. So, please, dont push developers to portability where it makes few or absolutely no sense.

Go to top
Re: Float display
Just popping in
Just popping in


See User information
@abalaban

Quote:

There was a time when mixing DOS I/O calls with C runtime I/O calls wasn't a good idea since then I try to not mix them as safety measure.

Indeed, this is not a good idea to mix them for standard I/O (unless you Flush() DOS streams and fflush() C streams between the two). However, if I got it right you just want to format a buffer, so here using snprintf() is not a problem at all since neither malloc() nor standard streams are involved. And if you are not in a shared library there is no issue with startup code. Maybe portability is not a good reason to use it, but code simplicity is, I would not extract by hand fractional part just to avoid using snprintf("%f")

Go to top
Re: Float display
Just popping in
Just popping in


See User information
Hehe, yes... but it would be even more simple to implement floating point output for SNPrintf(), so one doesnt have to hassle with the (possible) caveats of using a system call/C runtime call mix.

I never understood why they chose to call the "more modern" RawDoFmt-replacement exactly like the full-fledged C runtime call, but dont implement the full functionality (thats a reason to ask where it indeed IS more modern, besides the name).

It would have been more clever to keep RawDoFmt as THE absolute low-level-call it was all the time, and give the functionality developers would expect to the SNPrintf() call (even more as its located within utility.library and not within exec.library).

Or, if some basic ouput function detached from exec context is needed so badly, give it another name.

Go to top
Re: Float display
Just popping in
Just popping in


See User information
Quote:

I never understood why they chose to call the "more modern" RawDoFmt-replacement exactly like the full-fledged C runtime call, but dont implement the full functionality (thats a reason to ask where it indeed IS more modern, besides the name).

It seems quite obvious SNPrintf (just like ASPrintf) was only added to fill the gap missing in the RawDoFmt family (since there already was Printf, FPrint, VPrintf etc...), not to be compatible with snprintf. Same goes for StrlCat, StrlCpy... If you need C runtime flavours in a shared library, better use newlib. BTW, the new FormatString32() of locale.library seems quite useless now since AFAIK no system function make use of it.

Go to top
Re: Float display
Just popping in
Just popping in


See User information
There is still the question, why on earth there is still NO system function with the ability to output formatted strings containing float numbers. Or simply convert float numbers into a string, which in turn is copied to a string buffer, which in turn could be used by the well-known output functions.

utility.library would be a perfect place for functions like this.

Go to top
Re: Float display
Quite a regular
Quite a regular


See User information
@whose:
Because that would only duplicate library code. Utility.library uses the C runtime library, just as Centaurz's code does.

@abalaban:
Quote:

There was a time when mixing DOS I/O calls with C runtime I/O calls wasn't a good idea...


Where does DOS come into this? I thought you were using utility.library? That does not use DOS.

BTW, many OS components use IUtility->SNPrintf() and C runtime calls and mix them up (I do it in many places); and we don't have a problem.

cheers
tony
Go to top
Re: Float display
Just popping in
Just popping in


See User information
@tonyw:

You mean newlib, dont you? Well, the duplicating of library code argument would be futile then, as there is much more trouble to cure, if a program uses clib2 AND dos.library buffered file I/O calls additionally. And no documentation about all this and how to use it correctly, if you need some low-level functionality.

What a mess...

Go to top
Re: Float display
Quite a regular
Quite a regular


See User information
@whose:

I think the "mess" is of your own making. No one should be using clib2 these days, it is not thread-safe and is obsolete. There is no problem using newlib calls mixed with calls to utility.library, although it seems to me to be a duplication: I can do far more with an "sprintf()" in C than I can do using utility.library, and I can look it up in any C textbook.

I still don't see a problem, but I'll leave it at that, we're getting nowhere with this discussion.

cheers
tony
Go to top

  Register To Post
(1) 2 »

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project