Powered by Invision Power Board

 
    Reply to this topicStart new topicStart Poll

> RetroX shows off his fantastical C++ abilities
United States
RetroXYZ
Posted: Oct 1 2009, 06:26 PM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


I present you with...
STRING TO MATH

What does this do?

Type in "5 + 5"
What do you get?
10.

Type in "4*2"
What do you get?
8.

Type in "2+4*5"
What do you get?
22, not 30

It supports five basic operations (+, -, *, /, plus ^ for exponent). "x" can be used in place of * if you like. It uses order of operations and features parentheses as well. Also, multiplying without a * is fine, as well as positive and negative signs (2*-2, 2*+2). This means 2(5) would be the same as 2*5.

What could have been improved:
- Useless symbols are truncated, and don't return error (not just spaces, but extra letters will be ignored as opposed to showing an error).
- Syntax errors result in segmentation faults. Basically said, if you type in "5+", it will just end the program with error in Windows, and say "Segmentation fault" in bash or similar shells.
I'll probably fix these later.

Anyways, the source is included for the curious and for those who think it might be useful. I ask that if you use it, however, to give credit saying I made it (basically, don't go around saying you made it, since you didn't). It's in the form of a nice header.

The compiled Windows EXE and UNIX executable are included. The UNIX version should work on Mac, but I have no clue how Macs handle applications, so I wouldn't know. If someone has a Mac who can confirm this, please do.

I'd like to ask everyone that they attempt to break the program. If it breaks in any of the ways I listed, don't bother posting. But if some random expression fails to work, let me know.

Also, keep in mind that you have to remember the order of operations. Exponents are first. -4 is -1 * 4, so you'll end up taking 4 to the exponent, not -4. Any answer that makes a non-real number, for example, (-4)^0.5, will display "NaN". Don't bother mentioning that as an error - there's not much I can do about it, although I may eventually add support for imaginary numbers.

EDIT: teehee I forgot to include the zip

This post has been edited by RetroXYZ on Oct 1 2009, 06:27 PM

Attached File ( Number of downloads: 46 )
Attached File  C__.zip
PMEmail PosterMSN
Top
United States
Xgoff
Posted: Oct 1 2009, 06:40 PM
Quote Post


<):|
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03

Status: (0d) [--]


well you can check for nans so it's not all that hard to do something about them

it may be a little more difficult to check what caused the nan but i'm p sure at least some of those cases will be encoded in the floating point bit values


--------------------

This post may contain original research or unverified claims.
Please disregard the above information and contact an administrator.

DISCLAIMER: by sending me (xgoff) a private message, you agree to the directives and their terms specified henceforth:
DIRECTIVE 1 (APPLE): i may or may not reply promptly or at all; and there are no guarantees to the usefulness of the reply. i may not acknowledge whether i have even received your private message
DIRECTIVE 2 (CHILE CON CARNE): as per my view, "private" applies only to the initial transaction, and the material of your message may or may not be made public at my discretion; as this will more than likely be a post in the CCC or IRC, you may not be able to view it
DIRECTIVE 3 (FEATHER DUSTER): you must address me (xgoff) as "Sir Master Xgofficus his Highest and Most Awesome the Third"; failure to comply with this term may invoke one or both of the above directives, and i will leave a burning bag of **** on your doorstep
DIRECTIVE 4 (BOOTSTRAP): if you have read this disclaimer, please private message me promptly, in compliance with the above terms, so i can ensure you are capable of following directions you idiot
this concludes the test of the emergency disclaimer system, your scheduled programming will now continue. satisfaction guaranteed, and 100% cash back available under certain circumstances; restrictions may or may not apply within your place of residence
NOTICE: these directives and their terms may change at any time, without notice; as a private message transaction to myself assumes an understanding and full compliance of the above, you should ensure you are fully aware of the above terms at any point before sending a private message; any message received is assumed to have been sent in compliance with the above

QUOTE
(5:25:58 PM) Mikau: xgoff
(5:26:00 PM) Mikau: guess what
(5:26:04 PM) Xgoff: chicken butt
(5:26:09 PM) Mikau: **** you
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
RetroXYZ
Posted: Oct 1 2009, 06:51 PM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


QUOTE (Xgoff @ Oct 1 2009, 07:40 PM)
well you can check for nans so it's not all that hard to do something about them

it may be a little more difficult to check what caused the nan but i'm p sure at least some of those cases will be encoded in the floating point bit values

C++ has a complex number type header, but I was too lazy to include it.

This post has been edited by RetroXYZ on Oct 1 2009, 07:01 PM
PMEmail PosterMSN
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.0431 ]   [ 14 queries used ]   [ GZIP Enabled ]   [ Server Load: 1.42 ]