The parse-float Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The parse-float Reference Manual

This is the parse-float Reference Manual, generated automatically by Declt version 2.3 "Robert April" on Tue Feb 20 09:09:18 2018 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

This package exports the following function to parse floating-point values from a string in common lisp.

The information below is purposefully as close as possible to the text and format of parse-integer in the Common Lisp HyperSpec, but this package is not related to LispWorks in any way.

Syntax:

parse-float string &key start end radix junk-allowed decimal-character exponent-character type => float, pos

Arguments and Values:

string---a string.

start, end---bounding index designators of string. The defaults for start and end are 0 and nil, respectively.

radix---a radix. The default is 10.

junk-allowed---a generalized boolean. The default is false.

decimal-character---a character separating the integer and decimal parts. The default is #\..

exponent-character---the exponentiation character (case insensitive). The default is #\e.

type---a number type specifier. The default is *READ-DEFAULT-FLOAT-FORMAT*.

float---a float, depending on type, or false.

pos---a bounding index of string.

Description:

parse-float parses a float in the specified radix from the substring of string delimited by start and end into a number of the given type.

parse-float expects an optional sign (+ or -) followed by a a non-empty sequence of digits to be interpreted in the specified radix, optionally followed by decimal-character, a sequence of digits, exponent-character, a sign (+ or -) and a sequence of digits. Optional leading and trailing whitespace is ignored.

parse-float does not recognize the syntactic radix-specifier prefixes #O, #B, #X, and #nR, nor does it recognize the exponent if radix is not 10.

If junk-allowed is false, an error of type parse-error is signaled if substring does not consist entirely of the representation of a signed float, possibly surrounded on either side by whitespace characters.

The first value returned is either the float that was parsed, or else nil if no syntactically correct float was seen but junk-allowed was true.

The second value is either the index into the string of the delimiter that terminated the parse, or the upper bounding index of the substring if the parse terminated at the end of the substring (as is always the case if junk-allowed is false).

Examples:

Load the package parse-float using Quicklisp:

(ql:quickload "parse-float")

Import the parse-float function:

(use-package :parse-float)

Use the imported parse-float function:

(parse-float "123") => 123.0, 3

(parse-float "123.1" :start 1 :radix 5 :type 'double-float) => 13.2d0, 5

(parse-float "123,0D2" :decimal-character #\, :exponent-character #\d :type 'single-float) => 12300.0, 7

(parse-float "no-integer" :junk-allowed t) => NIL, 0

(parse-float "1.2e-3" :type 'number) => 3/2500, 6

Side Effects:

None.

Affected By:

None.

Exceptional Situations:

If junk-allowed is false, an error is signaled if substring does not consist entirely of the representation of a float, possibly surrounded on either side by whitespace characters.

See Also:

parse-integer, [parse-number] (https://github.com/sharplispers/parse-number "parse-number on Github")


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 parse-float

Author

Sumant Oemrawsingh

License

Public Domain

Description

Parse floating point values in strings.

Dependency

alexandria

Source

parse-float.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 parse-float.asd

Location

parse-float.asd

Systems

parse-float (system)


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.2 parse-float/package.lisp

Parent

parse-float (system)

Location

package.lisp

Packages

parse-float


Previous: , Up: Lisp files   [Contents][Index]

3.1.3 parse-float/parse-float.lisp

Dependency

package.lisp (file)

Parent

parse-float (system)

Location

parse-float.lisp

Exported Definitions

parse-float (function)

Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 parse-float

Source

package.lisp (file)

Use List
Exported Definitions

parse-float (function)

Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Functions

Function: parse-float STRING &key START END RADIX JUNK-ALLOWED DECIMAL-CHARACTER EXPONENT-CHARACTER TYPE

Similar to PARSE-INTEGER, but parses a floating point value and returns the value as the specified TYPE (by default *READ-DEFAULT-FLOAT-FORMAT*). The DECIMAL-CHARACTER (by default #.) specifies the separator between the integer and decimal parts, and the EXPONENT-CHARACTER (by default #e, case insensitive) specifies the character before the exponent. Note that the exponent is only parsed if RADIX is 10.

Package

parse-float

Source

parse-float.lisp (file)


Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Constants

Constant: +whitespace-characters+

List of whitespace characters

Package

parse-float

Source

parse-float.lisp (file)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.2 Functions

Function: parse-integer-only STRING &key START END RADIX ALLOW-SIGN

Parse an integer from a string, without skipping whitespaces. Returns three values: the integer, the position in the string that ended the parsing, and a boolean which is T if the parsing ended due to a whitespace or end of the string, and NIL otherwise. If allow-sign is NIL (T by default), also signs are not allowed in the string (i.e. cannot start with #+ or #-).

Package

parse-float

Source

parse-float.lisp (file)

Function: sign-char-p CHARACTER

Predicate for testing if CHARACTER is a sign character (i.e. #+ or #-).

Package

parse-float

Source

parse-float.lisp (file)

Function: skip-whitespaces STRING &key START END

For the substring in STRING delimited by START and END, skip all the whitespace at the beginning and return the index of the first non-whitespace character, or END if no non-whitespace characters were found.

Package

parse-float

Source

parse-float.lisp (file)

Function: whitespace-char-p CHARACTER

Predicate for testing if CHARACTER is a whitespace character.

Package

parse-float

Source

parse-float.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

5.2.3 Types

Type: bounding-index ()

A valid upper bound to a string.

Package

parse-float

Source

parse-float.lisp (file)

Type: string-index ()

A valid string index.

Package

parse-float

Source

parse-float.lisp (file)

Type: valid-radix ()

A valid Common Lisp radix.

Package

parse-float

Source

parse-float.lisp (file)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   F   L   P  
Index Entry  Section

F
File, Lisp, parse-float.asd: The parse-float<dot>asd file
File, Lisp, parse-float/package.lisp: The parse-float/package<dot>lisp file
File, Lisp, parse-float/parse-float.lisp: The parse-float/parse-float<dot>lisp file

L
Lisp File, parse-float.asd: The parse-float<dot>asd file
Lisp File, parse-float/package.lisp: The parse-float/package<dot>lisp file
Lisp File, parse-float/parse-float.lisp: The parse-float/parse-float<dot>lisp file

P
parse-float.asd: The parse-float<dot>asd file
parse-float/package.lisp: The parse-float/package<dot>lisp file
parse-float/parse-float.lisp: The parse-float/parse-float<dot>lisp file

Jump to:   F   L   P  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   F   P   S   W  
Index Entry  Section

F
Function, parse-float: Exported functions
Function, parse-integer-only: Internal functions
Function, sign-char-p: Internal functions
Function, skip-whitespaces: Internal functions
Function, whitespace-char-p: Internal functions

P
parse-float: Exported functions
parse-integer-only: Internal functions

S
sign-char-p: Internal functions
skip-whitespaces: Internal functions

W
whitespace-char-p: Internal functions

Jump to:   F   P   S   W  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   +  
C  
Index Entry  Section

+
+whitespace-characters+: Internal constants

C
Constant, +whitespace-characters+: Internal constants

Jump to:   +  
C  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   B   P   S   T   V  
Index Entry  Section

B
bounding-index: Internal types

P
Package, parse-float: The parse-float package
parse-float: The parse-float system
parse-float: The parse-float package

S
string-index: Internal types
System, parse-float: The parse-float system

T
Type, bounding-index: Internal types
Type, string-index: Internal types
Type, valid-radix: Internal types

V
valid-radix: Internal types

Jump to:   B   P   S   T   V