Writing square root in cplusplus

Pages: 12
Square root is available as the function sqrt() declared in <cmath>.
Oh dear! Another one.


Somebody else can get rid of him.
There. Now it looks like a PSA or something.
looks like a PSA

"Hey, kids, don't copy 'n' paste from another website just so you can be a spammer."

That what you lookin' for, helios?
Thanks for the tip!
What's a PSA?
Public Service Announcement
Pretty Stupid Answer
Personal Self Advice

They're like public information films.
Ah, I see.

#include <iostream>
void PSA(){std::cout << "        ____\n       /  K\n v =  / 2 -\n    \\/    m\n";}
int main()
What's a PSA?

Take your pick:
Take your pick:

I have to admit that, despite the 258 possible interpretations that list gives for Helios' post, I chuckled a bit at
Pot Smokers of America
Parrot Society of Australia

It may have started with a repost bot, but you learn something new every day.
A continuing topic started by a repost bot sure can be fun, can't it. Edumakashunal too.
since all we have is a title now, I would not mind a language where you had math symbols like sqrt and so on. With unicode, all that stuff is in it and more, though you would need some way to type them more efficiently.
So like LaTeX combined with Maxima? While I like its... terseness, I think we can all agree that mathematical notation is not the most reader-friendly language around. I think my favorite abuse of it is in the Ethereum whitepaper, where it specifies the EVM ISA and its semantics. It's like the writer went "just go ahead and try to figure out how to implement it!"
Not even that deep, just at an ease of use level, where you didn't need 4-5 letters to do one symbol.
ctrl+shift+u 221A (hit space)

Dang it, I thought I was on to something, but g++ does not accept the √ symbol in this form:
error: extended character √ is not valid in an identifier

I was trying to #define √ sqrt but hit this roadbloack. I'm trying to find an option to force g++ to accept it but nothing so far.

I've heard of programmable keyboards (though I've never used one), so I was curious if the symbol could be implemented on one of those.

Maybe there's a compiler on github that takes in unicode source files.
Last edited on
The preprocessor still works at the identifier level. You can't #define arbitrary strings of tokens as macros.
Good tip, with that I was able to do it with pi π, but that just looks like nonsense, why would π(30) return sqrt(30)? Too bad √ is not in the allowed list. Short of making a recommendation to the C/C++ standards committee, it looks like it's not happening any time soon.

I guess you could pick another greek symbol to represent sqrt(), but there's still the effort of getting a programmable keyboard.
Last edited on
You could #define that_nonnegative_number_whose_square_is sqrt .
Pages: 12