GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
fpclassify(n) Tcl Float Classifier fpclassify(n)


fpclassify - Floating point number classification of Tcl values

package require tcl 8.7

fpclassify value


The fpclassify command takes a floating point number, value, and returns one of the following strings that describe it:
zero
value is a floating point zero.
subnormal
value is the result of a gradual underflow.
normal
value is an ordinary floating-point number (not zero, subnormal, infinite, nor NaN).
infinite
value is a floating-point infinity.
nan
value is Not-a-Number.

The fpclassify command throws an error if value is not a floating-point value and cannot be converted to one.

This shows how to check whether the result of a computation is numerically safe or not. (Note however that it does not guard against numerical errors; just against representational problems.)

set value [command-that-computes-a-value]
switch [fpclassify $value] {
    normal - zero {
        puts "Result is $value"
    }
    infinite {
        puts "Result is infinite"
    }
    subnormal {
        puts "Result is $value - WARNING! precision lost"
    }
    nan {
        puts "Computation completely failed"
    }
}

expr(n), mathfunc(n)

floating point

This command depends on the fpclassify() C macro conforming to “ISO C99” (i.e., to ISO/IEC 9899:1999).

Copyright © 2018 by Kevin B. Kenny <kennykb@acm.org>. All rights reserved
8.7 Tcl

Search for    or go to Top of page |  Section n |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.