[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  Programming
. -> [Folder]  General
. . -> [Subject]  Help with a numbers solution

Help with a numbers solution

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Daniel Spain   (15 posts)  [Biography] bio
Date Thu 03 May 2012 07:09 PM (UTC)
Message
hello all back in the 90's using bcc 3.1 i wrote a mud for a bbs software and here recently i have been porting it to a standalone using Nick's barebones mud server.

i hit a compile error with this math function.


long ep2 = atoi(ltoa(((p->exp/(DEFEPL+axp))+1)));


to fix the compile error i adjusted it like so:


long ep2 = ((p->exp/(DEFEPL+axp))+1);


will this suffice or could i lose any of the value in the conversion?
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Fri 04 May 2012 03:39 AM (UTC)
Message
Quote:
atoi(ltoa(...))

What was the point of this?


https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Daniel Spain   (15 posts)  [Biography] bio
Date Reply #2 on Fri 04 May 2012 08:39 AM (UTC)
Message
Fiendish said:

Quote:
atoi(ltoa(...))

What was the point of this?




well when i got the codebase it was already a completed game, written in bcc 3.1 i finalized it and ported it to bcc 4.5 then bbsing went dormant we all moved on to other things well i picked it back up a few years ago and ported it to bcc 5.01 then to 5.5.1 and never had to touch most the code except maybe make a few changes just to get rid of annoying compiler warnings but with making it standalone i hit alot of errors just on things like the above code which is why i asked. i am no career developer by far all my knowledge has came from trial and error on this same codebase since the mid 90's and well since it worked won;t no need in fixing it and this porting project broke it so i had to fix it.
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Sat 05 May 2012 12:59 AM (UTC)

Amended on Sat 05 May 2012 01:02 AM (UTC) by Fiendish

Message
Daniel Spain said:

Fiendish said:

Quote:
atoi(ltoa(...))

What was the point of this?

well when i got the codebase it was already a completed game, written in bcc 3.1 i finalized it and ported it to bcc 4.5 then bbsing went dormant we all moved on to other things well i picked it back up a few years ago and ported it to bcc 5.01 then to 5.5.1 and never had to touch most the code except maybe make a few changes just to get rid of annoying compiler warnings but with making it standalone i hit alot of errors just on things like the above code which is why i asked. i am no career developer by far all my knowledge has came from trial and error on this same codebase since the mid 90's and well since it worked won;t no need in fixing it and this porting project broke it so i had to fix it.


I meant very specifically what is the point of taking a number, converting it to a string, and then converting the string back to a number? :)

Like 5->"5"->5

It looks to me like the original way had no value so you didn't lose anything by removing it.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #4 on Sat 05 May 2012 08:18 AM (UTC)
Message
It converts from a long to an int, stopping over in stringland in between. I don't think there's any harm in removing it, though you might want to find out how itoa handles values that are out-of-range. A simple cast might behave differently.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #5 on Sat 05 May 2012 02:03 PM (UTC)

Amended on Sat 05 May 2012 02:07 PM (UTC) by Fiendish

Message
Twisol said:

It converts from a long to an int, stopping over in stringland in between.
It then casts back to long. It's all kind of silly. In a 32 bit environment int and long are the same thing anyway in C.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #6 on Sun 06 May 2012 12:54 AM (UTC)
Message
Right, but the int -> long conversion is lossless. Good point about int and long in a 32-bit environment. Since it's probably a safe bet that this was written for a 32-bit computer, I'd say it's totally safe to remove.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


19,086 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]