Powerrangers123
Powerrangers123

Reputation: 11

How do you convert a character to a real in SML?

If I'm trying to do this:

Convert #”N” to a real

What ML expression would do this?

In the same way that:\

str = Char -> string
chr = int -> Char
ord = Char -> int
real = int -> real

Is there an ML expression like the ones stated above that can convert char -> real?

The input would be something like:

real #"N";

and the output would be:

val it = "whatever the value is": real

Upvotes: 1

Views: 192

Answers (1)

Ben
Ben

Reputation: 11

No you would need to use two functions:

real(ord(#"N"));

Breakdown:

ord(#"N"); ...... converts to ascii value, 78.

real(78); .......... converts int to real, 78.0.

Upvotes: 1

Related Questions