Help with a numbers solution

Posted by Daniel Spain on Thu 03 May 2012 07:09 PM — 7 posts, 28,972 views.

#0
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?
USA Global Moderator #1
Quote:
atoi(ltoa(...))

What was the point of this?

#2
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.
USA Global Moderator #3
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.
Amended on Sat 05 May 2012 01:02 AM by Fiendish
USA #4
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.
USA Global Moderator #5
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.
Amended on Sat 05 May 2012 02:07 PM by Fiendish
USA #6
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.