##### 4.3.2.4 Trigonometric Functions
> ```
(sin z)   →   number?
  z : number?```
Returns the sine of z, where z is in radians. The result is normally inexact, but it is exact 0 if z is exact 0.
Examples:
> ```racket
> > ( sin 3.14159 )
> 2.65358979335273e-6
> > ( sin 1.0+5.0i )
> 62.44551846769654+40.0921657779984i
> ```
> ```
(cos z)  →  number?
  z : number?
```

Returns the cosine of z, where z is in radians.

Examples:

> ```racket
> > ( cos 3.14159 )
> -0.9999999999964793
> > ( cos 1.0+5.0i )
> 40.09580630629883-62.43984868079963i
> ```

> ```
(tan z)  →  number?
  z : number?
```
Returns the tangent of z, where z is in radians. The result is normally inexact, but it is exact 0 if z is exact 0.
Examples:
> ```racket
> > ( tan 0.7854 )
> 1.0000036732118494
> > ( tan 1.0+5.0i )
> 8.2567198342296e-5+1.0000377833796008i
> ```
> ```
(asin z)  →  number?
  z : number?
```

Returns the arcsine in radians of z. The result is normally inexact, but it is exact 0 if z is exact 0.

Examples:

> ```racket
> > ( asin 0.25 )
> 0.25268025514207865
> > ( asin 1.0+5.0i )
> 0.1937931365549322+2.3309746530493123i
> ```

> ```
(acos z)  →  number?
  z : number?
```
Returns the arccosine in radians of z.
Examples:
> ```racket
> > ( acos 0.25 )
> 1.318116071652818
> > ( acos 1.0+5.0i )
> 1.3770031902399644-2.3309746530493123i
> ```
> ```
(atan z)  →  number?
  z : number?
(atan y x)  →  number?
  y : real?
  x : real?


# 4.2 Booleans
```
In the one-argument case, returns the arctangent of the inexact approximation of z, except that the result is an exact 0 for z as 0, and the exn:fail:contract:divide-by-zero exception is raised for z as exact 0+1i or exact 0-1i.

In the two-argument case, the result is roughly the same as (atan (/ (exact  →  inexact y)) (exact  →  inexact x)), but the signs of y and x determine the quadrant of the result. Moreover, a suitable angle is returned when y divided by x produces +nan.0 in the case that neither y nor x is +nan.0. Finally, if y is exact 0 and x is a positive number, the result is exact 0. If both x and y are exact 0, the exn:fail:contract:divide-by-zero exception is raised.

Examples:

> ```racket
> > ( atan 0.5 )
> 0.46364760900080615
> > ( atan 2 1 )
> 1.1071487177940904
> > ( atan -2 -1 )
> -2.0344439357957027
> > ( atan 1.0+5.0i )
> 1.530881333938778+0.19442614214700213i
> > ( atan +inf.0 -i nf.0 )
> 2.356194490192345
> ```

Changed in version 7.2.0.2 of package base: Changed to raise exn:fail:contract:divide-by-zero for 0+1i and 0-1i and to produce exact 0 for any positive x (not just exact values) when y is 0.

##### 4.3.2.5 Complex Numbers

> ```
(make-rectangular x y)   →   number?
  x : real?
  y : real?```

Creates a complex number with x as the real part and y as the imaginary part. That is, returns ([+](#%28def._%28%28quote._~23~25kernel%29._%2B%29%29) x ([*](#%28def._%28%28quote._~23~25kernel%29._%2A%29%29) y 0+1i)).

Example:

> ```racket
> > ( make-rectangular 3 4.0 )
> 3.0+4.0i
> ```

> ```
(make-polar magnitude angle)  →  number?
  magnitude : real?
  angle : real?
```


# 4.2 Booleans
Creates a complex number which, if thought of as a point, is magnitude away from the origin and is rotated angle radians counter clockwise from the positive x-axis. That is, returns (+ (* magnitude (cos angle)) (* magnitude (sin angle) 0+1i)).
Examples:
> ```racket
> > ( make-polar 10 ( * pi 1/2 ) )
> 6.123233995736766e-16+10.0i
> > ( make-polar 10 ( * pi 1/4 ) )
> 7.0710678118654755+7.071067811865475i
> ```
> ```
(real-part z)   →   real?
  z : number?```
Returns the real part of the complex number z in rectangle coordinates.
Examples:
> ```racket
> > ( real-part 3+4i )
> 3
> > ( real-part 5.0 )
> 5.0
> ```
> ```
(imag-part z)  →  real?
  z : number?
```

Returns the imaginary part of the complex number z in rectangle coordinates.

Examples:

> ```racket
> > ( imag-part 3+4i )
> 4
> > ( imag-part 5.0 )
> 0
> > ( imag-part 5.0+0.0i )
> 0.0
> ```

> ```
(magnitude z)  →  (and/c real? (not/c negative?))
  z : number?
```
Returns the magnitude of the complex number z in polar coordinates. A complex number with +inf.0 or -inf.0 as a component has magnitude +inf.0, even if the other component is +nan.0.
Examples:
> ```racket
> > ( magnitude -3 )
> 3
> > ( magnitude 3.0 )
> 3.0
> > ( magnitude 3+4i )
> 5
> ```
Changed in version 7.2.0.2 of package base: Changed to always return +inf.0 for a complex number with a +inf.0 or -inf.0 component.
> ```
(angle z)  →  real?
  z : number?


# 4.2 Booleans
```
Returns the angle of the complex number z in polar coordinates.

The result is guaranteed to be between (- pi) and pi, possibly equal to pi (but never equal to (- pi)).

Examples:

> ```racket
> > ( angle -3 )
> 3.141592653589793
> > ( angle 3.0 )
> 0
> > ( angle 3+4i )
> 0.9272952180016122
> > ( angle +inf.0+inf.0i )
> 0.7853981633974483
> > ( angle -1 )
> 3.141592653589793
> ```

##### 4.3.2.6 Bitwise Operations

> ```
(bitwise-ior n ...) → exact-integer?
  n : exact-integer?```

Returns the bitwise “inclusive or” of the ns in their (semi-infinite) two’s complement representation. If no arguments are provided, the result is 0.

Examples:

> ```racket
> > ( bitwise-ior 1 2 )
> 3
> > ( bitwise-ior -3 2 1 )
> -31
> ```

> ```
(bitwise-and n ...) → exact-integer?
  n : exact-integer?
```
Returns the bitwise “and” of the ns in their (semi-infinite) two’s complement representation. If no arguments are provided, the result is -1.
Examples:
> ```racket
> > ( bitwise-and 1 2 )
> 0
> > ( bitwise-and -3 2 -1 )
> -32
> ```
> ```
(bitwise-xor n ...) → exact-integer?
  n : exact-integer?```
Returns the bitwise “exclusive or” of the ns in their (semi-infinite) two’s complement representation. If no arguments are provided, the result is 0.
Examples:
> ```racket
> > ( bitwise-xor 1 5 )
> 4
> > ( bitwise-xor -3 2 -1 )
> 31
> ```
> ```
(bitwise-not n)  →  exact-integer?
  n : exact-integer?


# 4.2 Booleans
```

Returns the bitwise “not” of n in its (semi-infinite) two’s complement representation.

Examples:

> ```racket
> > ( bitwise-not 5 )
> -6
> > ( bitwise-not -1 )
> 0
> ```

> ```
(bitwise-bit-set? n m)  →  boolean?
  n : exact-integer?
  m : exact-nonnegative-integer?
```
Returns #t when the mth bit of n is set in n’s (semi-infinite) two’s complement representation.
This operation is equivalent to ([not](booleans.html#%28def._%28%28quote._~23~25kernel%29._not%29%29) ([zero?](number-types.html#%28def._%28%28quote._~23~25kernel%29._zero~3f%29%29) ([bitwise-and](#%28def._%28%28quote._~23~25kernel%29._bitwise-and%29%29) n ([arithmetic-shift](#%28def._%28%28quote._~23~25kernel%29._arithmetic-shift%29%29) 1 m)))), but it is faster and runs in constant time when n is positive.
Examples:
> ```racket
> > ( bitwise-bit-set? 5 0 )
> #t
> > ( bitwise-bit-set? 5 2 )
> #t
> > ( bitwise-bit-set? -5 ( expt 2 700 ) )
> #t
> ```
> ```
(bitwise-first-bit-set n)  →  exact-integer?
  n : exact-integer?


# 4.2 Booleans
```
Returns -1 if n is 0, otherwise returns the smallest m for which (bitwise-bit-set? n m) produces #t.

Example:

> ```racket
> > ( bitwise-first-bit-set 128 )
> 7
> ```

Added in version 8.16.0.4 of package base.

This operation is equivalent to (not (zero? (bitwise-and n (arithmetic-shift 1 m)))), but it is faster and runs in constant time when n is positive.

Examples:

> ```racket
> > ( bitwise-bit-set? 5 0 )
> #t
> > ( bitwise-bit-set? 5 2 )
> #t
> > ( bitwise-bit-set? -5 ( expt 2 700 ) )
> #t
> ```

}

> ```
(bitwise-bit-field n start end) → exact-integer?
  n : exact-integer?
  start : exact-nonnegative-integer?
   end   :   ( and/c exact-nonnegative-integer?
> ( >=/c start ) )```

Extracts the bits between position start and ([-](#%28def._%28%28quote._~23~25kernel%29._-%29%29) end 1) (inclusive) from n and shifts them down to the least significant portion of the number.

This operation is equivalent to the computation

> ```racket
> ( bitwise-and ( sub1 ( arithmetic-shift 1 ( - end start ) ) )
> ( arithmetic-shift n ( - start ) ) )
> ```

but it runs in constant time when n is positive, start and end are fixnums, and ([-](#%28def._%28%28quote._~23~25kernel%29._-%29%29) end start) is no more than the maximum width of a fixnum.

Each pair of examples below uses the same numbers, showing the result both in binary and as integers.

Examples:

> ```racket
> > ( format "~b" ( bitwise-bit-field ( string->number "1101" 2 ) 1 1 ) )
> "0"
> > ( bitwise-bit-field 13 1 1 )
> 0
> > ( format "~b" ( bitwise-bit-field ( string->number "1101" 2 ) 1 3 ) )
> "10"
> > ( bitwise-bit-field 13 1 3 )
> 2
> > ( format "~b" ( bitwise-bit-field ( string->number "1101" 2 ) 1 4 ) )
> "110"
> > ( bitwise-bit-field 13 1 4 )
> 6
> ```

> ```
(arithmetic-shift n m)  →  exact-integer?
  n : exact-integer?
  m : exact-integer?
```


# 4.2 Booleans
Returns the bitwise “shift” of n in its (semi-infinite) two’s complement representation. If m is non-negative, the integer n is shifted left by m bits; i.e., m new zeros are introduced as rightmost digits. If m is negative, n is shifted right by (- m) bits; i.e., the rightmost m digits are dropped.
Examples:
> ```racket
> > ( arithmetic-shift 1 10 )
> 1024
> > ( arithmetic-shift 255 -3 )
> 31
> ```
> ```
(integer-length n)   →   exact-integer?
  n : exact-integer?```
Returns the number of bits in the (semi-infinite) two’s complement representation of n after removing all leading zeros (for non-negative n) or ones (for negative n).
Examples:
> ```racket
> > ( integer-length 8 )
> 4
> > ( integer-length -8 )
> 3
> ```


##### 4.3.2.7 Random Numbers
> ```
(current-pseudo-random-generator)	→
(-> integer-in 1 4294967087)
```
(parameter)	→
(-> integer-in 0 (sub1 (expt 2 31)))```

Seeds the current pseudo-random number generator with k. Seeding a generator sets its internal state deterministically; that is, seeding a generator with a particular number forces it to produce a sequence of pseudo-random numbers that is the same across runs and across platforms.

The [random-seed](#%28def._%28%28quote._~23~25kernel%29._random-seed%29%29) function is convenient for some purposes, but note that the space of states for a pseudo-random number generator is much larger that the space of allowed values for k. Use [vector->pseudo-random-generator!](#%28def._%28%28quote._~23~25kernel%29._vector-~3epseudo-random-generator%21%29%29) to set a pseudo-random number generator to any of its possible states.

> ```
(make-pseudo-random-generator)  →  pseudo-random-generator?
```
(current-milliseconds)	→```
Returns #t if v is a pseudo-random number generator, #f otherwise.
> ```
(current-pseudo-random-generator)	→
(-> current-pseudo-random-generator rand-gen)
(current-pseudo-random-generator rand-gen) → void?
    rand-gen	:
(-> current-pseudo-random-generator rand-gen)


# 4.2 Booleans
```
A parameter that determines the pseudo-random number generator used by random.

> ```
(pseudo-random-generator  →  vector rand-gen)
   →   pseudo-random-generator-vector?
  rand-gen : pseudo-random-generator?```

Produces a vector that represents the complete internal state of rand-gen. The vector is suitable as an argument to [vector->pseudo-random-generator](#%28def._%28%28quote._~23~25kernel%29._vector-~3epseudo-random-generator%29%29) to recreate the generator in its current state (across runs and across platforms).

> ```
(vector  →  pseudo-random-generator vec)
  →  pseudo-random-generator?
  vec : pseudo-random-generator-vector?
```
(parameter)	→```
Like [vector->pseudo-random-generator](#%28def._%28%28quote._~23~25kernel%29._vector-~3epseudo-random-generator%29%29), but changes rand-gen to the given state, instead of creating a new generator.
> ```
(pseudo-random-generator-vector? v)  →  boolean?
  v : any/c


# 4.2 Booleans
```
Returns #t if v is a vector of six exact integers, where the first three integers are in the range 0 to 4294967086, inclusive; the last three integers are in the range 0 to 4294944442, inclusive; at least one of the first three integers is non-zero; and at least one of the last three integers is non-zero. Otherwise, the result is #f.

##### 4.3.2.8 Other Randomness Utilities

|  |  |
|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  (require racket/random) |  package: base |

> ```
(crypto-random-bytes n) → bytes?
  n : exact-positive-integer?```

Provides an interface to randomness from the underlying operating system. Use [crypto-random-bytes](#%28def._%28%28lib._racket%2Frandom..rkt%29._crypto-random-bytes%29%29) instead of [random](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._random%29%29) wherever security is a concern.

Returns n random bytes. On Unix systems, the bytes are obtained from "/dev/urandom", while Windows uses the RtlGenRand system function.

Example:

> ```racket
> > ( crypto-random-bytes 14 )
> #"\0\1\1\2\3\5\b\r\25\"7Y\220\351"
> ```

Added in version 6.3 of package base.

> ```
(current-pseudo-random-generator)	→
(-> current-pseudo-random-generator)
```
(current-pseudo-random-generator)	→
(-> listof any/c)```


# 4.2 Booleans
Returns a list of n elements of seq, picked at random, listed in any order. If replacement? is non-false, elements are drawn with replacement, which allows for duplicates.
Like [sequence-length](sequences.html#%28def._%28%28lib._racket%2Fsequence..rkt%29._sequence-length%29%29), does not terminate on infinite sequences, and evaluates the entire sequence.
Added in version 6.4 of package base.


##### 4.3.2.9 Number–String Conversions
> ```
(number → string z [radix) → string?
  z : number?
  radix : (or/c 2 8 10 16) = 10
```
Returns a string that is the printed form of z (see Printing Numbers) in the base specified by radix. If z is inexact, radix must be 10, otherwise the exn:fail:contract exception is raised.

Examples:

> ```racket
> > ( number  →  string 3.0 )
> "3.0"
> > ( number  →  string 255 8 )
> "377"
> ```

> ```
(string → number s
   [ radix
    convert-mode
    decimal-mode
    single-mode)

   →   (or/c number? #f string? extflonum?)
  s : string?
  radix : (integer-in 2 16) = 10
   convert-mode   :   (or/c 'number-or-false 'read)
      =   'number-or-false

   decimal-mode   :   (or/c 'decimal-as-inexact 'decimal-as-exact)
      =   ( if ( read-decimal-as-inexact )
> ' decimal-as-inexact
> ' decimal-as-exact )

   single-mode   :   (or/c 'single 'double)
      =   ( if ( read-single-flonum )
> ' single
> ' double )```

Reads and returns a number datum from s (see [Reading Numbers](reader.html#%28part._parse-number%29)). The optional radix argument specifies the default base for the number, which can be overridden by #b, #o, #d, or #x in the string.

If convert-mode is 'number-or-false, the result is #f if s does not parse exactly as a number datum (with no whitespace). If convert-mode is 'read, the result can be an [extflonum](extflonums.html#%28tech._extflonum%29), and it can be a string that contains an error message if [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29) of s would report a reader exception (but the result can still be #f if [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29) would report a symbol).

The decimal-mode argument controls number parsing the same way that the [read-decimal-as-inexact](Reading.html#%28def._%28%28quote._~23~25kernel%29._read-decimal-as-inexact%29%29) parameter affects [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29).

The single-mode argument controls number parsing the same way that the [read-single-flonum](Reading.html#%28def._%28%28quote._~23~25kernel%29._read-single-flonum%29%29) parameter affects [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29).

Examples:

> ```racket
> > ( string->number "3.0+2.5i" )
> 3.0+2.5i
> > ( string->number "hello" )
> #f
> > ( string->number "111" 7 )
> 57
> > ( string->number "#b111" 7 )
> 7
> > ( string->number "#e+inf.0" 10 ' read )
> "no exact representation for +inf.0"
> > ( string->number "10.3" 10 ' read ' decimal-as-exact )
> 103/10
> ```

Changed in version 6.8.0.2 of package base: Added the convert-mode and decimal-mode arguments.
Changed in version 7.3.0.5: Added the single-mode argument.

> ```
(real → decimal-string n [decimal-digits) → string?
  n : rational?
  decimal-digits : exact-nonnegative-integer? = 2
```


# 4.2 Booleans
Prints n into a string and returns the string. The printed form of n shows exactly decimal-digits digits after the decimal point. The printed form uses a minus sign if n is negative, and it does not use a plus sign if n is positive.
Before printing, n is converted to an exact number, multiplied by (expt 10 decimal-digits), rounded, and then divided again by (expt 10 decimal-digits). The result of this process is an exact number whose decimal representation has no more than decimal-digits digits after the decimal (and it is padded with trailing zeros if necessary).
If n is a real number with no decimal representation (e.g. +nan.0, +inf.0), then the exn:fail:contract exception is raised. (Any real number that is convertible to decimal notation is rational, so n must be rational?, despite the name of the function.)
Examples:
> ```racket
> > ( real  →  decimal-string pi )
> "3.14"
> > ( real  →  decimal-string pi 5 )
> "3.14159"
> ```
> ```
(integer-bytes → integer bstr
    signed?
   [ big-endian?
    start
    end)    →    exact-integer?
  bstr : bytes?
  signed? : any/c
  big-endian? : any/c = (system-big-endian?)
  start : exact-nonnegative-integer? = 0
  end : exact-nonnegative-integer? = (bytes-length bstr)```


# 4.2 Booleans
Converts the machine-format number encoded in bstr to an exact integer. The start and end arguments specify the substring to decode, where ([-](#%28def._%28%28quote._~23~25kernel%29._-%29%29) end start) must be 1, 2, 4, or 8. If signed? is true, then the bytes are decoded as a two’s-complement number, otherwise it is decoded as an unsigned integer. If big-endian? is true, then the first byte’s value provides the most significant eight bits of the number, otherwise the first byte provides the least-significant eight bits, and so on.
Changed in version 6.10.0.1 of package base: Added support for decoding a 1-byte string.
> ```
(integer → integer-bytes n
    size-n
    signed?
   [ big-endian?
    dest-bstr
    start)    →    bytes?
  n : exact-integer?
  size-n : (or/c 1 2 4 8)
  signed? : any/c
  big-endian? : any/c = (system-big-endian?)
   dest-bstr   :   (and/c bytes? (not/c immutable?))
      =   (make-bytes size-n)
  start : exact-nonnegative-integer? = 0


# 4.2 Booleans
```
Converts the exact integer n to a machine-format number encoded in a byte string of length size-n, which must be 1, 2, 4, or 8. If signed? is true, then the number is encoded as two’s complement, otherwise it is encoded as an unsigned bit stream. If big-endian? is true, then the most significant eight bits of the number are encoded in the first byte of the resulting byte string, otherwise the least-significant bits are encoded in the first byte, and so on.

The dest-bstr argument must be a mutable byte string of length size-n. The encoding of n is written into dest-bstr starting at offset start, and dest-bstr is returned as the result.

If n cannot be encoded in a byte string of the requested size and format, the exn:fail:contract exception is raised. If dest-bstr is not of length size-n, the exn:fail:contract exception is raised.

Changed in version 6.10.0.1 of package base: Added support for encoding a 1-byte value.

> ```
(floating-point-bytes → real bstr
   [ big-endian?
    start
    end)    →    flonum?

  bstr : bytes?
  big-endian? : any/c = (system-big-endian?)
  start : exact-nonnegative-integer? = 0
  end : exact-nonnegative-integer? = (bytes-length bstr)```

Converts the IEEE floating-point number encoded in bstr from position start (inclusive) to end (exclusive) to an inexact real number. The difference between start an end must be either 4 or 8 bytes. If big-endian? is true, then the first byte’s ASCII value provides the most significant eight bits of the IEEE representation, otherwise the first byte provides the least-significant eight bits, and so on.

> ```
(real → floating-point-bytes x
    size-n
   [ big-endian?
    dest-bstr
    start)    →    bytes?

  x : real?
  size-n : (or/c 4 8)
  big-endian? : any/c = (system-big-endian?)
   dest-bstr   :   (and/c bytes? (not/c immutable?))
      =   (make-bytes size-n)

  start : exact-nonnegative-integer? = 0
```


# 4.2 Booleans
Converts the real number x to its IEEE representation in a byte string of length size-n, which must be 4 or 8. If big-endian? is true, then the most significant eight bits of the number are encoded in the first byte of the resulting byte string, otherwise the least-significant bits are encoded in the first character, and so on.
The dest-bstr argument must be a mutable byte string of length size-n. The encoding of n is written into dest-bstr starting with byte start, and dest-bstr is returned as the result.
If dest-bstr is provided and it has less than start plus size-n bytes, the exn:fail:contract exception is raised.
> ```
(system-big-endian?)   →   boolean?```
Returns #t if the native encoding of numbers is big-endian for the machine running Racket, #f if the native encoding is little-endian.


##### 4.3.2.10 Extra Constants and Functions
|                                                                                |                                                                                |
|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/math](#%28mod-path._racket%2Fmath%29)) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |
The bindings documented in this section are provided by the [racket/math](#%28mod-path._racket%2Fmath%29) and [racket](index.html) libraries, but not [racket/base](index.html).
>
<colgroup><col style="width: 100%" /></colgroup>

value

[pi](#%28def._%28%28lib._racket%2Fmath..rkt%29._pi%29%29) : [flonum?](number-types.html#%28def._%28%28quote._~23~25kernel%29._flonum~3f%29%29)

An approximation of π, the ratio of a circle’s circumference to its diameter.
Examples:


# 4.2 Booleans
> ```racket
> > pi
> 3.141592653589793
> > ( cos pi )
> -1.0
> ```
>
<colgroup><col style="width: 100%" /></colgroup>

value

[pi.f](#%28def._%28%28lib._racket%2Fmath..rkt%29._pi..f%29%29) : ([or/c](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._or%2Fc%29%29) [single-flonum?](number-types.html#%28def._%28%28quote._~23~25kernel%29._single-flonum~3f%29%29) [flonum?](number-types.html#%28def._%28%28quote._~23~25kernel%29._flonum~3f%29%29))

The same value as [pi](#%28def._%28%28lib._racket%2Fmath..rkt%29._pi%29%29), but as a single-precision floating-point number if the current platform supports it.
Changed in version 7.3.0.5 of package base: Allow value to be a double-precision flonum.
> ```
(degrees  →  radians x)  →  real?
  x : real?
```

Converts an x-degree angle to radians.

Examples:

> ```racket
> > ( degrees->radians 180 )
> 3.141592653589793
> > ( sin ( degrees->radians 45 ) )
> 0.7071067811865475
> ```

> ```
(radians  →  degrees x)  →  real?
  x : real?
```
Converts x radians to degrees.
Examples:
> ```racket
> > ( radians->degrees pi )
> 180.0
> > ( radians->degrees ( * 1/4 pi ) )
> 45.0
> ```
> ```
(sqr z)  →  number?
  z : number?


# 4.2 Booleans
```
Returns (* z z).

> ```
(sgn x) → (or/c (=/c -1) (=/c 0) (=/c 1) +nan.0 +nan.f)
  x : real?```

Returns the sign of x as either -1, 0 (or a signed-zero variant, when inexact), 1, or not-a-number.

Examples:

> ```racket
> > ( sgn 10 )
> 1
> > ( sgn -1 0.0 )
> -1.0
> > ( sgn 0 )
> 0
> > ( sgn -0 .0 )
> -0.0
> > ( sgn 0.0 )
> 0.0
> > ( sgn +nan.0 )
> +nan.0
> > ( sgn +inf.0 )
> 1.0
> > ( sgn -i nf.0 )
> -1.0
> ```

> ```
(conjugate z)  →  number?
  z : number?
```
Returns the complex conjugate of z.
Examples:
> ```racket
> > ( conjugate 1 )
> 1
> > ( conjugate 3+4i )
> 3-4i
> ```
> ```
(sinh z)  →  number?
  z : number?
```

Returns the hyperbolic sine of z.

> ```
(cosh z)  →  number?
  z : number?
```
Returns the hyperbolic cosine of z.
> ```
(tanh z)  →  number?
  z : number?
```

Returns the hyperbolic tangent of z.

> ```
(exact-round x)  →  exact-integer?
  x : rational?
```
Equivalent to (inexact  →  exact (round x)).
> ```
(exact-floor x)   →   exact-integer?
  x : rational?```
Equivalent to ([inexact->exact](number-types.html#%28def._%28%28quote._~23~25kernel%29._inexact-~3eexact%29%29) ([floor](#%28def._%28%28quote._~23~25kernel%29._floor%29%29) x)).
> ```
(exact-ceiling x)  →  exact-integer?
  x : rational?


# 4.2 Booleans
```
Equivalent to (inexact  →  exact (ceiling x)).

> ```
(exact-truncate x)   →   exact-integer?
  x : rational?```

Equivalent to ([inexact->exact](number-types.html#%28def._%28%28quote._~23~25kernel%29._inexact-~3eexact%29%29) ([truncate](#%28def._%28%28quote._~23~25kernel%29._truncate%29%29) x)).

> ```
(order-of-magnitude r)  →  (and/c exact? integer?)
  r : (and/c real? positive?)
```
Computes the greatest exact integer m such that:
> ```racket
> ( <= ( expt 10 m )> ( inexact  →  exact r ) )
> ```
Hence also:
> ```racket
> ( < ( inexact  →  exact r )
> ( expt 10 ( add1 m ) ) )
> ```
Examples:
> ```racket
> > ( order-of-magnitude 999 )
> 2
> > ( order-of-magnitude 1000 )
> 3
> > ( order-of-magnitude 1/100 )
> -2
> > ( order-of-magnitude 1/101 )
> -3
> ```
> ```
(nan? x) → boolean?
  x : real?```
Returns #t if x is [eqv?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eqv~3f%29%29) to +nan.0 or +nan.f; otherwise #f.
> ```
(infinite? x)  →  boolean?
  x : real?
```

Returns #t if x is +inf.0, -inf.0, +inf.f, -inf.f; otherwise #f.

> ```
(positive-integer? x)  →  boolean?
  x : any/c
```
Like [exact-positive-integer?](number-types.html#%28def._%28%28quote._~23~25kernel%29._exact-positive-integer~3f%29%29), but also returns #t for positive [inexact?](number-types.html#%28def._%28%28quote._~23~25kernel%29._inexact~3f%29%29) integers.
Added in version 6.8.0.2 of package base.
> ```
(negative-integer? x)  →  boolean?
  x : any/c


# 4.2 Booleans
```
The same as (and (integer? x) (negative? x)).

Added in version 6.8.0.2 of package base.

> ```
(nonpositive-integer? x)   →   boolean?
  x : any/c```

The same as ([and](if.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._and%29%29) ([integer?](number-types.html#%28def._%28%28quote._~23~25kernel%29._integer~3f%29%29) x) ([not](booleans.html#%28def._%28%28quote._~23~25kernel%29._not%29%29) ([positive?](number-types.html#%28def._%28%28quote._~23~25kernel%29._positive~3f%29%29) x))).

Added in version 6.8.0.2 of package base.

> ```
(nonnegative-integer? x)  →  boolean?
  x : any/c
```
Like exact-nonnegative-integer?, but also returns #t for non-negative inexact? integers.
Added in version 6.8.0.2 of package base.
> ```
(natural? x)   →   boolean?
  x : any/c```
An alias for [exact-nonnegative-integer?](number-types.html#%28def._%28%28quote._~23~25kernel%29._exact-nonnegative-integer~3f%29%29).
Added in version 6.8.0.2 of package base.
------------------------------------------------------------------------


# 4.3.3 Flonums


#### 4.3.3 Flonums
|                                                                                |                                                                                |
|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/flonum]()) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |
The [racket/flonum]() library provides operations like [fl+](#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl%2B%29%29) that consume and produce only [flonums](numbers.html#%28tech._flonum%29). Flonum-specific operations can provide better performance when used consistently, and they are as safe as generic operations like [+](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2B%29%29).


# 4.3.3 Flonums
> > > <img src="finger.png" width="24" height="24" alt="+" />See also [Fixnum and Flonum Optimizations](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=performance.html%23%2528part._fixnums%252Bflonums%2529&version=8.18.0.13) in [The Racket Guide](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=index.html&version=8.18.0.13).


##### 4.3.3.1 Flonum Arithmetic
> ```
(fl+ a ...) → flonum?
  a : flonum?
(fl- a b ...)  →  flonum?
  a : flonum?
  b : flonum?
(fl* a ...)  →  flonum?
  a : flonum?
(fl/ a b ...)  →  flonum?
  a : flonum?
  b : flonum?
(flabs a)  →  flonum?
  a : flonum?
```
Like +, -, *, /, and abs, but constrained to consume flonums. The result is always a flonum.

Changed in version 7.0.0.13 of package base: Allow zero or more arguments for fl+ and fl* and one or more arguments for fl- and fl/.

> ```
(fl= a b ...) → boolean?
  a : flonum?
  b : flonum?

([fl

(fl> a b ...)   →   boolean?
  a : flonum?
  b : flonum?

([fl

(fl>= a b ...)   →   boolean?
  a : flonum?
  b : flonum?

(flmin a b ...)   →   flonum?
  a : flonum?
  b : flonum?

(flmax a b ...)   →   flonum?
  a : flonum?
  b : flonum?```

Like [=](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._~3d%29%29), [<](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._~3c%29%29), [>](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._~3e%29%29), [<=](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._~3c~3d%29%29), [>=](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._~3e~3d%29%29), [min](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._min%29%29), and [max](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._max%29%29), but constrained to consume [flonums](numbers.html#%28tech._flonum%29).

Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.

> ```
(flround a)  →  flonum?
  a : flonum?

(flfloor a)  →  flonum?
  a : flonum?

(flceiling a)  →  flonum?
  a : flonum?

(fltruncate a)  →  flonum?
  a : flonum?
```


# 4.3.3 Flonums
Like round, floor, ceiling, and truncate, but constrained to consume flonums.
> ```
(flsingle a)   →   flonum?
  a : flonum?```
Returns a value like a, but potentially discards precision and range so that the result can be represented as a single-precision IEEE floating-point number (even if [single-flonums](numbers.html#%28tech._single._flonum%29) are not supported).
Using [flsingle](#%28def._%28%28lib._racket%2Fflonum..rkt%29._flsingle%29%29) on the arguments and results of [fl+](#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl%2B%29%29), [fl-](#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl-%29%29), [fl*](#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl%2A%29%29), [fl/](#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl%2F%29%29), and [flsqrt](#%28def._%28%28lib._racket%2Fflonum..rkt%29._flsqrt%29%29)—that is, performing double-precision operations on values representable in single precision and then rounding the result to single precision—is always the same as performing the corresponding single-precision operation \[[Roux14](doc-bibliography.html#%28cite._.Roux14%29)\]. (For other operations, the IEEE floating-point specification does not make enough guarantees to say more about the interaction with [flsingle](#%28def._%28%28lib._racket%2Fflonum..rkt%29._flsingle%29%29).)
Added in version 7.8.0.7 of package base.
> ```
(flbit-field a start end)  →  exact-nonnegative-integer?
  a : flonum?
  start : (integer-in 0 64)
  end : (integer-in 0 64)


# 4.3.3 Flonums
```

Extracts a range of bits from the 64-bit IEEE representation of a, returning the non-negative integer that has the same bits set in its (semi-infinite) two’s complement representation.

Examples:

> ```racket
> > ( flbit-field -0 .0 63 64 )
> 1
> > ( format "~x" ( flbit-field 3.141579e+132 16 48 ) )
> "b43544f2"
> ```

Added in version 8.15.0.3 of package base.

> ```
(flsin a)  →  flonum?
  a : flonum?

(flcos a)  →  flonum?
  a : flonum?

(fltan a)  →  flonum?
  a : flonum?

(flasin a)  →  flonum?
  a : flonum?

(flacos a)  →  flonum?
  a : flonum?

(flatan a)  →  flonum?
  a : flonum?

(fllog a)  →  flonum?
  a : flonum?

(flexp a)  →  flonum?
  a : flonum?

(flsqrt a)  →  flonum?
  a : flonum?
```


# 4.3.3 Flonums
Like [sin](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._sin%29%29), [cos](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._cos%29%29), [tan](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._tan%29%29), [asin](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._asin%29%29), [acos](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._acos%29%29), [atan](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._atan%29%29), [log](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._log%29%29), [exp](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._exp%29%29), and [sqrt](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._sqrt%29%29), but constrained to consume and produce [flonums](numbers.html#%28tech._flonum%29). The result is +nan.0 when a number outside the range -1.0 to 1.0 is given to [flasin](#%28def._%28%28lib._racket%2Fflonum..rkt%29._flasin%29%29) or [flacos](#%28def._%28%28lib._racket%2Fflonum..rkt%29._flacos%29%29), or when a negative number is given to [fllog](#%28def._%28%28lib._racket%2Fflonum..rkt%29._fllog%29%29) or [flsqrt](#%28def._%28%28lib._racket%2Fflonum..rkt%29._flsqrt%29%29).
> ```
(flexpt a b)  →  flonum?
  a : flonum?
  b : flonum?


# 4.3.3 Flonums
```

Like [expt](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._expt%29%29), but constrained to consume and produce [flonums](numbers.html#%28tech._flonum%29).

Due to the result constraint, the results compared to [expt](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._expt%29%29) differ in the following cases: These special cases correspond to pow in C99 \[[C99](doc-bibliography.html#%28cite._.C99%29)\].

-   ([flexpt](#%28def._%28%28lib._racket%2Fflonum..rkt%29._flexpt%29%29) -1.0 +inf.0) — 1.0

-   ([flexpt](#%28def._%28%28lib._racket%2Fflonum..rkt%29._flexpt%29%29) a +inf.0) where a is negative — ([expt](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._expt%29%29) ([abs](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._abs%29%29) a) +inf.0)

-   ([flexpt](#%28def._%28%28lib._racket%2Fflonum..rkt%29._flexpt%29%29) a -inf.0) where a is negative — ([expt](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._expt%29%29) ([abs](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._abs%29%29) a) -inf.0)

-

    ([expt](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._expt%29%29) -inf.0 b) where b is a non-integer:

    -   b is negative — 0.0

    -   b is positive — +inf.0

-   ([flexpt](#%28def._%28%28lib._racket%2Fflonum..rkt%29._flexpt%29%29) a b) where a is negative and b is not an integer — +nan.0

> ```
(  →  fl a)  →  flonum?
  a : exact-integer?
```


# 4.3.3 Flonums
Like [exact->inexact](number-types.html#%28def._%28%28quote._~23~25kernel%29._exact-~3einexact%29%29), but constrained to consume exact integers, so the result is always a [flonum](numbers.html#%28tech._flonum%29).
> ```
(fl  →  exact-integer a)  →  exact-integer?
  a : flonum?
```
Like inexact  →  exact, but constrained to consume an integer flonum, so the result is always an exact integer.

> ```
(make-flrectangular a b)
   →    ( and/c complex?
> ( lambda ( c ) ( flonum? ( real-part c ) ) )
> ( lambda ( c ) ( flonum? ( imag-part c ) ) ) )

  a : flonum?
  b : flonum?

(flreal-part a)   →   flonum?
   a   :   ( and/c complex?
> ( lambda ( c ) ( flonum? ( real-part c ) ) )
> ( lambda ( c ) ( flonum? ( imag-part c ) ) ) )

(flimag-part a)   →   flonum?
   a   :   ( and/c complex?
> ( lambda ( c ) ( flonum? ( real-part c ) ) )
> ( lambda ( c ) ( flonum? ( imag-part c ) ) ) )```

Like [make-rectangular](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._make-rectangular%29%29), [real-part](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._real-part%29%29), and [imag-part](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._imag-part%29%29), but both parts of the complex number must be inexact.

> ```
(flrandom rand-gen)  →  (and flonum? (>/c 0) ([
```
Equivalent to (random rand-gen).


##### 4.3.3.2 Flonum Vectors
A flvector is like a vector, but it holds only inexact real numbers. This representation can be more compact, and unsafe operations on flvectors (see racket/unsafe/ops) can execute more efficiently than unsafe operations on vectors of inexact reals.
An f64vector as provided by ffi/vector stores the same kinds of values as a flvector, but with extra indirections that make f64vectors more convenient for working with foreign libraries. The lack of indirections makes unsafe flvector access more efficient.
Two flvectors are equal? if they have the same length, and if the values in corresponding slots of the flvectors are equal?.
A printed flvector starts with #fl(, optionally with a number between the #fl and (. See Reading Vectors for information on reading flvectors and Printing Vectors for information on printing flvectors.
> ```
(flvector? v)   →   boolean?
  v : any/c```
Returns #t if v is a [flvector](#%28tech._flvector%29), #f otherwise.
> ```
(flvector x ...) → flvector?
  x : flonum?
```
Creates a flvector containing the given inexact real numbers.

Example:

> ```racket
> > ( flvector 2.0 3.0 4.0 5.0 )
> (flvector 2.0 3.0 4.0 5.0)
> ```

> ```
(make-flvector size [x) → flvector?
  size : exact-nonnegative-integer?
  x : flonum? = 0.0```

Creates a [flvector](#%28tech._flvector%29) with size elements, where every slot in the [flvector](#%28tech._flvector%29) is filled with x.

Example:

> ```racket
> > ( make-flvector 4 3.0 )
> (flvector 3.0 3.0 3.0 3.0)
> ```

> ```
(flvector-length vec)  →  exact-nonnegative-integer?
  vec : flvector?
```


# 4.3.3 Flonums
Returns the length of vec (i.e., the number of slots in the flvector).
> ```
(flvector-ref vec pos)   →   flonum?
  vec : flvector?
  pos : exact-nonnegative-integer?```
Returns the inexact real number in slot pos of vec. The first slot is position 0, and the last slot is one less than ([flvector-length](#%28def._%28%28lib._racket%2Fflonum..rkt%29._flvector-length%29%29) vec).
> ```
(flvector-set! vec pos x)  →  flonum?
  vec : flvector?
  pos : exact-nonnegative-integer?
  x : flonum?
```
Sets the inexact real number in slot pos of vec. The first slot is position 0, and the last slot is one less than (flvector-length vec).

> ```
(flvector-copy vec [start end) → flvector?
  vec : flvector?
  start : exact-nonnegative-integer? = 0
  end : exact-nonnegative-integer? = (vector-length v)```

Creates a fresh [flvector](#%28tech._flvector%29) of size ([-](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._-%29%29) end start), with all of the elements of vec from start (inclusive) to end (exclusive).

> ```
(in-flvector vec [start stop step) → sequence?
  vec : flvector?
  start : exact-nonnegative-integer? = 0
  stop : (or/c exact-integer? #f) = #f
  step : (and/c exact-integer? (not/c zero?)) = 1
```
Returns a sequence equivalent to vec when no optional arguments are supplied.
The optional arguments start, stop, and step are as in in-vector.
A in-flvector application can provide better performance for flvector iteration when it appears directly in a for clause.


# 4.3.3 Flonums
>
<colgroup><col style="width: 100%" /></colgroup>

<colgroup><col style="width: 100%" /></colgroup>

syntax

(for/flvector maybe-length (for-clause ...) body ...)

<colgroup><col style="width: 100%" /></colgroup>

syntax

(for*/flvector maybe-length (for-clause ...) body ...)

<colgroup><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /></colgroup>

maybe-length	 	=

 	 	|	 	#:length length-expr

 	 	|	 	#:length length-expr #:fill fill-expr

  	length-expr	 	:	 	exact-nonnegative-integer?

  	fill-expr	 	:	 	flonum?


# 4.3.3 Flonums
Like for/vector or for*/vector, but for flvectors. The default fill-expr produces 0.0.
> ```
(shared-flvector x ...) → flvector?
  x : flonum?```
Creates a [flvector](#%28tech._flvector%29) containing the given inexact real numbers. For communication among [places](places.html#%28tech._place%29), the new [flvector](#%28tech._flvector%29) is allocated in the [shared memory space](places.html#%28tech._shared._memory._space%29).
Example:
> ```racket
> > ( shared-flvector 2.0 3.0 4.0 5.0 )
> (flvector 2.0 3.0 4.0 5.0)
> ```
> ```
(make-shared-flvector size [x) → flvector?
  size : exact-nonnegative-integer?
  x : flonum? = 0.0


# 4.3.3 Flonums
```
Creates a flvector with size elements, where every slot in the flvector is filled with x. For communication among places, the new flvector is allocated in the shared memory space.

Example:

> ```racket
> > ( make-shared-flvector 4 3.0 )
> (flvector 3.0 3.0 3.0 3.0)
> ```

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

# 4.3.4 Fixnums

#### 4.3.4 Fixnums

|  |  |
|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  (require [racket/fixnum]()) |  package: base |

The [racket/fixnum]() library provides operations like fx+ that consume and produce only fixnums. The operations in this library are meant to be safe versions of unsafe operations like unsafe-fx+. These safe operations are generally no faster than using generic primitives like +.

The expected use of the [racket/fixnum]() library is for code where the require of [racket/fixnum]() is replaced with

> > > See the documentation of filtered-in for use with #lang racket/base.

> ```racket
> ( require ( filtered-in
> ( λ ( name )
> ( and ( regexp-match #rx"^unsafe-fx" name )
> ( regexp-replace #rx"unsafe-" name "" ) ) )
> racket/unsafe/ops ) )
> ```

to drop in unsafe versions of the library. Alternately, when encountering crashes with code that uses unsafe fixnum operations, use the [racket/fixnum]() library to help debug the problems.

##### 4.3.4.1 Fixnum Arithmetic

> ```
(fx+ a ...) → fixnum?
  a : fixnum?

(fx- a b ...)   →   fixnum?
  a : fixnum?
  b : fixnum?

(fx* a ...)   →   fixnum?
  a : fixnum?

(fxquotient a b)   →   fixnum?
  a : fixnum?
  b : fixnum?

(fxremainder a b)   →   fixnum?
  a : fixnum?
  b : fixnum?

(fxmodulo a b)   →   fixnum?
  a : fixnum?
  b : fixnum?

(fxabs a)   →   fixnum?
  a : fixnum?```

Safe versions of [unsafe-fx+](unsafe.html#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fx%2B%29%29), [unsafe-fx-](unsafe.html#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fx-%29%29), [unsafe-fx*](unsafe.html#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fx%2A%29%29), [unsafe-fxquotient](unsafe.html#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fxquotient%29%29), [unsafe-fxremainder](unsafe.html#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fxremainder%29%29), [unsafe-fxmodulo](unsafe.html#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fxmodulo%29%29), and [unsafe-fxabs](unsafe.html#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fxabs%29%29). The [exn:fail:contract:non-fixnum-result](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract~3anon-fixnum-result%29%29) exception is raised if the arithmetic result would not be a fixnum.

Changed in version 7.0.0.13 of package base: Allow zero or more arguments for [fx+](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fx%2B%29%29) and [fx*](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fx%2A%29%29) and one or more arguments for [fx-](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fx-%29%29).

> ```
(fxand a ...) → fixnum?
  a : fixnum?

(fxior a ...)  →  fixnum?
  a : fixnum?

(fxxor a ...)  →  fixnum?
  a : fixnum?

(fxnot a)  →  fixnum?
  a : fixnum?

(fxlshift a b)  →  fixnum?
  a : fixnum?
  b : fixnum?

(fxrshift a b)  →  fixnum?
  a : fixnum?
  b : fixnum?
```


# 4.3.3 Flonums
Like bitwise-and, bitwise-ior, bitwise-xor, bitwise-not, and arithmetic-shift, but constrained to consume fixnums; the result is always a fixnum. The unsafe-fxlshift and unsafe-fxrshift operations correspond to arithmetic-shift, but require non-negative arguments; unsafe-fxlshift is a positive (i.e., left) shift, and unsafe-fxrshift is a negative (i.e., right) shift, where the number of bits to shift must be no more than the number of bits used to represent a fixnum. The exn:fail:contract:non-fixnum-result exception is raised if the arithmetic result would not be a fixnum.
Changed in version 7.0.0.13 of package base: Allow any number of arguments for fxand, fxior, and fxxor.
> ```
(fxpopcount a)   →   fixnum?
  a : (and/c fixnum? (not/c negative?))
(fxpopcount32 a)   →   fixnum?
  a : (and/c fixnum? (integer-in 0 #xFFFFFFFF))
(fxpopcount16 a)   →   fixnum?
  a : (and/c fixnum? (integer-in 0 #xFFFF))```
Counts the number of bits in the two’s complement representation of a. Depending on the platform, the [fxpopcount32](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxpopcount32%29%29) and [fxpopcount16](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxpopcount16%29%29) operations can be faster when the result is known to be no more than 32 or 16, respectively.
Added in version 8.5.0.7 of package base.
> ```
(fx+/wraparound a b) → fixnum?
  a : fixnum?
  b : fixnum?
(fx-/wraparound [a] b)  →  fixnum?
  a : fixnum? = 0
  b : fixnum?
(fx*/wraparound a b)  →  fixnum?
  a : fixnum?
  b : fixnum?
(fxlshift/wraparound a b)  →  fixnum?
  a : fixnum?
  b : fixnum?


# 4.3.3 Flonums
```
Like fx+, fx-, fx*, and fxlshift, but a fixnum result is produced for any allowed arguments (i.e., for any fixnum argument, except that the second fxlshift/wraparound argument must be between 0 and the number of bits in a fixnum, inclusive). The result is produced by simply discarding bits that do not fit in a fixnum representation. The result is negative if the highest of the retained bits is set—even, for example, if the value was produced by adding two positive fixnums.

Added in version 7.9.0.6 of package base.
Changed in version 8.15.0.12: Changed fx-/wraparound to accept a single argument.

> ```
(fxrshift/logical a b)   →   fixnum?
  a : fixnum?
  b : fixnum?```

Shifts the bits in a to the right by b, filling in with zeros. With the sign bit treated as just another bit, a logical right-shift of a negative-signed fixnum can produce a large positive fixnum. For example, ([fxrshift/logical](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxrshift%2Flogical%29%29) -1 1) produces ([most-positive-fixnum](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._most-positive-fixnum%29%29)), illustrating that logical right-shift results are platform-dependent.

Examples:

> ```racket
> > ( fxrshift/logical 128 2 )
> 32
> > ( fxrshift/logical 255 4 )
> 15
> > ( = ( fxrshift/logical -1 1 ) ( most-positive-fixnum ) )
> #t
> ```

Added in version 8.8.0.5 of package base.

> ```
(fx= a b ...) → boolean?
  a : fixnum?
  b : fixnum?

([fx

(fx> a b ...)  →  boolean?
  a : fixnum?
  b : fixnum?

([fx

(fx>= a b ...)  →  boolean?
  a : fixnum?
  b : fixnum?

(fxmin a b ...)  →  fixnum?
  a : fixnum?
  b : fixnum?

(fxmax a b ...)  →  fixnum?
  a : fixnum?
  b : fixnum?
```


# 4.3.3 Flonums
Like =, <, >, <=, >=, min, and max, but constrained to consume fixnums.
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
> ```
(fx → fl a) → flonum?
  a : fixnum?
(fl  →  fx fl)   →   fixnum?
  fl : flonum?```
Conversion between [fixnums](numbers.html#%28tech._fixnum%29) and [flonums](numbers.html#%28tech._flonum%29) with truncation in the case of converting a [flonum](numbers.html#%28tech._flonum%29) to a [fixnum](numbers.html#%28tech._fixnum%29).
The [fx->fl](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fx-~3efl%29%29) function is the same as [exact->inexact](number-types.html#%28def._%28%28quote._~23~25kernel%29._exact-~3einexact%29%29) or [->fl](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._-~3efl%29%29) constrained to a fixnum argument.
The [fl->fx](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fl-~3efx%29%29) function is the same as [truncate](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._truncate%29%29) followed by [inexact->exact](number-types.html#%28def._%28%28quote._~23~25kernel%29._inexact-~3eexact%29%29) or [fl->exact-integer](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl-~3eexact-integer%29%29) constrained to returning a fixnum. If the truncated flonum does not fit into a fixnum, the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised.
Changed in version 7.7.0.8 of package base: Changed [fl->fx](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fl-~3efx%29%29) to truncate.
> ```


# 4.3.3 Flonums
(fixnum-for-every-system? v)  →  boolean?
  v : any/c
```
Returns #t if v is a fixnum and is represented by fixnum by every Racket implementation, #f otherwise.

Added in version 7.3.0.11 of package base.

##### 4.3.4.2 Fixnum Vectors

A fxvector is like a vector, but it holds only fixnums. The only advantage of a fxvector over a vector is that a shared version can be created with functions like shared-fxvector.

Two fxvectors are equal? if they have the same length, and if the values in corresponding slots of the fxvectors are equal?.

A printed fxvector starts with #fx(, optionally with a number between the #fx and (. See Reading Vectors for information on reading fxvectors and Printing Vectors for information on printing fxvectors.

> ```
(fxvector? v)   →   boolean?
  v : any/c```

Returns #t if v is a [fxvector](#%28tech._fxvector%29), #f otherwise.

> ```
(fxvector x ...) → fxvector?
  x : fixnum?
```
Creates a fxvector containing the given fixnums.
Example:
> ```racket
> > ( fxvector 2 3 4 5 )
> (fxvector 2 3 4 5)
> ```
> ```
(make-fxvector size [x) → fxvector?
  size : exact-nonnegative-integer?
  x : fixnum? = 0```
Creates a [fxvector](#%28tech._fxvector%29) with size elements, where every slot in the [fxvector](#%28tech._fxvector%29) is filled with x.
Example:
> ```racket
> > ( make-fxvector 4 3 )
> (fxvector 3 3 3 3)
> ```
> ```
(fxvector-length vec)  →  exact-nonnegative-integer?
  vec : fxvector?


# 4.3.3 Flonums
```
Returns the length of vec (i.e., the number of slots in the fxvector).

> ```
(fxvector-ref vec pos)   →   fixnum?
  vec : fxvector?
  pos : exact-nonnegative-integer?```

Returns the [fixnum](numbers.html#%28tech._fixnum%29) in slot pos of vec. The first slot is position 0, and the last slot is one less than ([fxvector-length](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxvector-length%29%29) vec).

> ```
(fxvector-set! vec pos x)  →  fixnum?
  vec : fxvector?
  pos : exact-nonnegative-integer?
  x : fixnum?
```
Sets the fixnum in slot pos of vec. The first slot is position 0, and the last slot is one less than (fxvector-length vec).
> ```
(fxvector-copy vec [start end) → fxvector?
  vec : fxvector?
  start : exact-nonnegative-integer? = 0
  end : exact-nonnegative-integer? = (vector-length v)```
Creates a fresh [fxvector](#%28tech._fxvector%29) of size ([-](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._-%29%29) end start), with all of the elements of vec from start (inclusive) to end (exclusive).
> ```
(in-fxvector vec [start stop step) → sequence?
  vec : fxvector?
  start : exact-nonnegative-integer? = 0
  stop : (or/c exact-integer? #f) = #f
  step : (and/c exact-integer? (not/c zero?)) = 1


# 4.3.3 Flonums
```
Returns a sequence equivalent to vec when no optional arguments are supplied.

The optional arguments start, stop, and step are as in in-vector.

An in-fxvector application can provide better performance for fxvector iteration when it appears directly in a for clause.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(for/fxvector maybe-length (for-clause ...) body ...)</p></blockquote></td></tr></tbody></table></td></tr><tr><td><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>syntax</p>

<p>(for*/fxvector maybe-length (for-clause ...) body ...)</p></blockquote></td></tr><tr><td> </td></tr><tr><td><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /></colgroup><tbody><tr><td style="text-align: right;" data-valign="baseline">maybe-length</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">=</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"><pre><code></code></pre></td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:length length-expr</td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:length length-expr #:fill fill-expr</td></tr></tbody></table></td></tr><tr><td> </td></tr><tr><td><blockquote><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td>  </td><td>length-expr</td><td> </td><td>:</td><td> </td><td>exact-nonnegative-integer?</td></tr></tbody></table><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td>  </td><td>fill-expr</td><td> </td><td>:</td><td> </td><td>fixnum?</td></tr></tbody></table></blockquote></td></tr></tbody></table></td></tr></tbody></table>

Like for/vector or for*/vector, but for fxvectors. The default fill-expr produces 0.

> ```
(shared-fxvector x ...) → fxvector?
  x : fixnum?```

Creates a [fxvector](#%28tech._fxvector%29) containing the given [fixnums](numbers.html#%28tech._fixnum%29). For communication among [places](places.html#%28tech._place%29), the new [fxvector](#%28tech._fxvector%29) is allocated in the [shared memory space](places.html#%28tech._shared._memory._space%29).

Example:

> ```racket
> > ( shared-fxvector 2 3 4 5 )
> (fxvector 2 3 4 5)
> ```

> ```
(make-shared-fxvector size [x) → fxvector?
  size : exact-nonnegative-integer?
  x : fixnum? = 0
```


# 4.3.3 Flonums
Creates a fxvector with size elements, where every slot in the fxvector is filled with x. For communication among places, the new fxvector is allocated in the shared memory space.
Example:
> ```racket
> > ( make-shared-fxvector 4 3 )
> (fxvector 3 3 3 3)
> ```


##### 4.3.4.3 Fixnum Range
> ```
(most-positive-fixnum)   →   fixnum?
(most-negative-fixnum)   →   fixnum?```
Returns the largest-magnitude positive and negative [fixnums](numbers.html#%28tech._fixnum%29). The values of ([most-positive-fixnum](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._most-positive-fixnum%29%29)) and ([most-negative-fixnum](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._most-negative-fixnum%29%29)) depend on the platform and virtual machine, but all fixnums are in the range ([most-negative-fixnum](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._most-negative-fixnum%29%29)) to ([most-positive-fixnum](#%28def._%28%28lib._racket%2Ffixnum..rkt%29._most-positive-fixnum%29%29)) inclusive, and all exact integers in that range are fixnums.
Added in version 8.1.0.7 of package base.
------------------------------------------------------------------------


# 4.3.5 Extflonums


#### 4.3.5 Extflonums
|                                                                                |                                                                                |
|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/extflonum]()) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |
An extflonum is an extended-precision (80-bit) floating-point number. Extflonum arithmetic is supported on platforms with extended-precision hardware and where the extflonum implementation does not conflict with normal double-precision arithmetic (i.e., on x86 and x86_64 platforms when Racket is compiled to use SSE instructions for floating-point operations, and on Windows when "longdouble.dll" is available).
A extflonum is not a [number](numbers.html#%28tech._number%29) in the sense of [number?](number-types.html#%28def._%28%28quote._~23~25kernel%29._number~3f%29%29). Only extflonum-specific operations such as [extfl+](#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extfl%2B%29%29) perform extflonum arithmetic.


# 4.3.5 Extflonums
A literal extflonum is written like an [inexact number](numbers.html#%28tech._inexact._number%29), but using an explicit t or T exponent marker (see [Reading Extflonums](reader.html#%28part._parse-extflonum%29)). For example, 3.5t0 is an extflonum. The extflonum values for infinity are +inf.t and -inf.t. The extflonum value for not-a-number is +nan.t or -nan.t.
If ([extflonum-available?](#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extflonum-available~3f%29%29)) produces #f, then all operations exported by [racket/extflonum]() raise [exn:fail:unsupported](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3aunsupported%29%29), except for [extflonum?](#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extflonum~3f%29%29), [extflonum-available?](#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extflonum-available~3f%29%29), and [extflvector?](#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extflvector~3f%29%29) (which always work). The reader (see [The Reader](reader.html)) always accepts extflonum input; when extflonum operations are not supported, printing an extflonum from the reader uses its source notation (as opposed to normalizing the format).


# 4.3.5 Extflonums
Two extflonums are [equal?](Equality.html#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29) along the same lines as [flonums](numbers.html#%28tech._flonum%29): when they are [extfl=](#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extfl~3d%29%29) and have the same sign (which matters for -0.0t0 and +0.0t0), or when they are both +nan.t. If extflonums are not supported on a platform, extflonums are [equal?](Equality.html#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29) only if they are [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29).
> ```
(extflonum? v)  →  boolean?
  v : any/c
```

Returns #t if v is an extflonum, #f otherwise.

> ```
(extflonum-available?)  →  boolean?
```
Returns #t if [extflonum](#%28tech._extflonum%29) operations are supported on the current platform, #f otherwise.


##### 4.3.5.1 Extflonum Arithmetic
> ```
(extfl+ a b)  →  extflonum?
  a : extflonum?
  b : extflonum?
(extfl- a b)  →  extflonum?
  a : extflonum?
  b : extflonum?
(extfl* a b)  →  extflonum?
  a : extflonum?
  b : extflonum?
(extfl/ a b)  →  extflonum?
  a : extflonum?
  b : extflonum?
(extflabs a)  →  extflonum?
  a : extflonum?
```
Like fl+, fl-, fl*, fl/, and flabs, but for extflonums.

> ```
(extfl= a b) → boolean?
  a : extflonum?
  b : extflonum?

([extfl

(extfl> a b)   →   boolean?
  a : extflonum?
  b : extflonum?

([extfl

(extfl>= a b)   →   boolean?
  a : extflonum?
  b : extflonum?

(extflmin a b)   →   extflonum?
  a : extflonum?
  b : extflonum?

(extflmax a b)   →   extflonum?
  a : extflonum?
  b : extflonum?```

Like [fl=](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl~3d%29%29), [fl<](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl~3c%29%29), [fl>](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl~3e%29%29), [fl<=](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl~3c~3d%29%29), [fl>=](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl~3e~3d%29%29), [flmin](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flmin%29%29), and [flmax](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flmax%29%29), but for [extflonums](#%28tech._extflonum%29).

> ```
(extflround a)  →  extflonum?
  a : extflonum?

(extflfloor a)  →  extflonum?
  a : extflonum?

(extflceiling a)  →  extflonum?
  a : extflonum?

(extfltruncate a)  →  extflonum?
  a : extflonum?
```


# 4.3.5 Extflonums
Like flround, flfloor, flceiling, and fltruncate, but for extflonums.
> ```
(extflsin a)   →   extflonum?
  a : extflonum?
(extflcos a)   →   extflonum?
  a : extflonum?
(extfltan a)   →   extflonum?
  a : extflonum?
(extflasin a)   →   extflonum?
  a : extflonum?
(extflacos a)   →   extflonum?
  a : extflonum?
(extflatan a)   →   extflonum?
  a : extflonum?
(extfllog a)   →   extflonum?
  a : extflonum?
(extflexp a)   →   extflonum?
  a : extflonum?
(extflsqrt a)   →   extflonum?
  a : extflonum?
(extflexpt a b)   →   extflonum?
  a : extflonum?
  b : extflonum?```
Like [flsin](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flsin%29%29), [flcos](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flcos%29%29), [fltan](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fltan%29%29), [flasin](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flasin%29%29), [flacos](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flacos%29%29), [flatan](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flatan%29%29), [fllog](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fllog%29%29), [flexp](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flexp%29%29), and [flsqrt](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flsqrt%29%29), and [flexpt](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flexpt%29%29), but for [extflonums](#%28tech._extflonum%29).
> ```
(  →  extfl a)  →  extflonum?
  a : exact-integer?
(extfl  →  exact-integer a)  →  exact-integer?
  a : extflonum?


# 4.3.5 Extflonums
(real  →  extfl a)  →  extflonum?
  a : real?
(extfl  →  exact a)  →  (and/c real? exact?)
  a : extflonum?
(extfl  →  fx a)  →  fixnum?
  a : extflonum?
(fx  →  extfl a)  →  extflonum?
  a : fixnum?
(extfl  →  inexact a)  →  flonum?
  a : extflonum?
```
The first six are like  →  fl, fl  →  exact-integer, real  →  double-flonum, inexact  →  exact, fl  →  fx, and fx  →  fl, but for extflonums. The extfl  →  inexact function converts a extflonum to its closest flonum approximation.

Changed in version 7.7.0.8 of package base: Changed extfl  →  fx to truncate.

##### 4.3.5.2 Extflonum Constants

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>value</p>

<p>pi.t : extflonum?</p></blockquote></td></tr></tbody></table>

Like pi, but with 80 bits precision.

##### 4.3.5.3 Extflonum Vectors

An extflvector is like an flvector, but it holds only extflonums. See also Unsafe Extflonum Operations.

Two extflvectors are equal? if they have the same length, and if the values in corresponding slots of the extflvectors are equal?.

> ```
(extflvector? v) → boolean?
  v : any/c

(extflvector x ...)   →   extflvector?
  x : extflonum?

(make-extflvector size [x)   →   extflvector?
  size : exact-nonnegative-integer?
  x : extflonum? = 0.0t0

(extflvector-length vec)   →   exact-nonnegative-integer?
  vec : extflvector?

(extflvector-ref vec pos)   →   extflonum?
  vec : extflvector?
  pos : exact-nonnegative-integer?

(extflvector-set! vec pos x)   →   extflonum?
  vec : extflvector?
  pos : exact-nonnegative-integer?
  x : extflonum?

(extflvector-copy vec [start end)   →   extflvector?
  vec : extflvector?
  start : exact-nonnegative-integer? = 0
  end : exact-nonnegative-integer? = (vector-length v)```

Like [flvector?](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flvector~3f%29%29), [flvector](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flvector%29%29), [make-flvector](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._make-flvector%29%29), [flvector-length](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flvector-length%29%29), [flvector-ref](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flvector-ref%29%29), flvector-set, and [flvector-copy](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flvector-copy%29%29), but for [extflvectors](#%28tech._extflvector%29).

> ```
(in-extflvector vec [start stop step) → sequence?
  vec : extflvector?
  start : exact-nonnegative-integer? = 0
  stop : (or/c exact-integer? #f) = #f
  step : (and/c exact-integer? (not/c zero?)) = 1

syntax

(for/extflvector maybe-length (for-clause ...) body ...)

syntax

(for*/extflvector maybe-length (for-clause ...) body ...)

maybe-length   =
    |   #:length length-expr
    |   #:length length-expr #:fill fill-expr

   length-expr   :   exact-nonnegative-integer?
   fill-expr   :   extflonum?
```


# 4.3.5 Extflonums
Like in-flvector, for/flvector, and for*/flvector, but for extflvectors.
> ```
(shared-extflvector x ...) → extflvector?
  x : extflonum?
(make-shared-extflvector size [x)   →   extflvector?
  size : exact-nonnegative-integer?
  x : extflonum? = 0.0t0```
Like [shared-flvector](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._shared-flvector%29%29) and [make-shared-flvector](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._make-shared-flvector%29%29), but for [extflvectors](#%28tech._extflvector%29).


##### 4.3.5.4 Extflonum Byte Strings
> ```
(floating-point-bytes → extfl bstr
   [ big-endian?
    start
    end)    →    extflonum?
  bstr : bytes?
  big-endian? : any/c = (system-big-endian?)
  start : exact-nonnegative-integer? = 0
  end : exact-nonnegative-integer? = (bytes-length bstr)
```
Like floating-point-bytes  →  real, but for extflonums: Converts the extended-precision floating-point number encoded in bstr from position start (inclusive) to end (exclusive) to an extflonum. The difference between start an end must be 10 bytes.

> ```
(extfl → floating-point-bytes x
   [ big-endian?
    dest-bstr
    start)    →    bytes?

  x : extflonum?
  big-endian? : any/c = (system-big-endian?)
   dest-bstr   :   (and/c bytes? (not/c immutable?))
      =   (make-bytes 10)

  start : exact-nonnegative-integer? = 0```

Like [real->floating-point-bytes](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._real-~3efloating-point-bytes%29%29), but for [extflonums](#%28tech._extflonum%29): Converts x to its representation in a byte string of length 10.

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

# 4.4 Strings

### 4.4 Strings

> > > <img src="finger.png" width="24" height="24" alt="+" />[Strings (Unicode)](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=strings.html&version=8.18.0.13) in [The Racket Guide](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=index.html&version=8.18.0.13) introduces strings.

A string is a fixed-length array of [characters](characters.html).

A string can be mutable or immutable. When an immutable string is provided to a procedure like [string-set!](#%28def._%28%28quote._~23~25kernel%29._string-set%21%29%29), the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised. String constants generated by the default reader (see [Reading Strings](reader.html#%28part._parse-string%29)) are immutable, and they are [interned](reader.html#%28tech._interned%29) in [read-syntax](Reading.html#%28def._%28%28quote._~23~25kernel%29._read-syntax%29%29) mode. Use [immutable?](booleans.html#%28def._%28%28quote._~23~25kernel%29._immutable~3f%29%29) to check whether a string is immutable.

Two strings are [equal?](Equality.html#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29) when they have the same length and contain the same sequence of characters.

A string can be used as a single-valued sequence (see [Sequences](sequences.html)). The characters of the string serve as elements of the sequence. See also [in-string](sequences.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._in-string%29%29).

See [Reading Strings](reader.html#%28part._parse-string%29) for information on [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29)ing strings and [Printing Strings](printing.html#%28part._print-string%29) for information on [print](Writing.html#%28def._%28%28quote._~23~25kernel%29._print%29%29)ing strings.

See also: [immutable?](booleans.html#%28def._%28%28quote._~23~25kernel%29._immutable~3f%29%29), [symbol->string](symbols.html#%28def._%28%28quote._~23~25kernel%29._symbol-~3estring%29%29), [bytes->string/utf-8](bytestrings.html#%28def._%28%28quote._~23~25kernel%29._bytes-~3estring%2Futf-8%29%29).

#### 4.4.1 String Constructors, Selectors, and Mutators

> ```
(string? v)  →  boolean?
  v : any/c
```


# 4.3.5 Extflonums
Returns #t if v is a string, #f otherwise.
See also immutable-string? and mutable-string?.
Examples:
> ```racket
> > ( string? "Apple" )
> #t
> > ( string? ' apple )
> #f
> ```
> ```
(make-string k [char) → string?
  k : exact-nonnegative-integer?
  char : char? = #\nul```
Returns a new mutable string of length k where each position in the string is initialized with the character char.
Example:
> ```racket
> > ( make-string 5 #\z )
> "zzzzz"
> ```
> ```
(string char ...) → string?
  char : char?
```

Returns a new mutable string whose length is the number of provided chars, and whose positions are initialized with the given chars.

Example:

> ```racket
> > ( string #\A #\p #\p #\l #\e )
> "Apple"
> ```

> ```
(string  →  immutable-string str)  →  (and/c string? immutable?)
  str : string?
```
Returns an immutable string with the same content as str, returning str itself if str is immutable.
Examples:
> ```racket
> > ( immutable? ( string #\H #\e #\l #\l #\o ) )
> #f
> > ( immutable? ( string->immutable-string ( string #\H #\e #\l #\l #\o ) ) )
> #t
> ```
> ```
(string-length str)  →  exact-nonnegative-integer?
  str : string?
```

Returns the length of str.

Example:

> ```racket
> > ( string-length "Apple" )
> 5
> ```

> ```
(string-ref str k)  →  char?
  str : string?
  k : exact-nonnegative-integer?
```


# 4.3.5 Extflonums
Returns the character at position k in str. The first position in the string corresponds to 0, so the position k must be less than the length of the string, otherwise the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised.
Example:
> ```racket
> > ( string-ref "Apple" 0 )
> #\A
> ```
> ```
(parameter)	→
(-> and/c string? (not/c immutable?))
```
Changes the character position k in str to char. The first position in the string corresponds to 0, so the position k must be less than the length of the string, otherwise the exn:fail:contract exception is raised.

Examples:

> ```racket
> > ( define s ( string #\A #\p #\p #\l #\e ) )
> > ( string-set! s 4 #\y )
> > s
> "Apply"
> ```

> ```
(substring str start [end) → string?
  str : string?
  start : exact-nonnegative-integer?
  end : exact-nonnegative-integer? = (string-length str)```

Returns a new mutable string that is ([-](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._-%29%29) end start) characters long, and that contains the same characters as str from start inclusive to end exclusive. The first position in a string corresponds to 0, so the start and end arguments must be less than or equal to the length of str, and end must be greater than or equal to start, otherwise the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised.

Examples:

> ```racket
> > ( substring "Apple" 1 3 )
> "pp"
> > ( substring "Apple" 1 )
> "pple"
> ```

> ```
(string-copy str)  →  string?
  str : string?
```


# 4.3.5 Extflonums
(parameter)	→
(-> and/c string? (not/c immutable?))```
Changes the characters of dest starting at position dest-start to match the characters in src from src-start (inclusive) to src-end (exclusive), where the first position in a string corresponds to 0. The strings dest and src can be the same string, and in that case the destination region can overlap with the source region; the destination characters after the copy match the source characters from before the copy. If any of dest-start, src-start, or src-end are out of range (taking into account the sizes of the strings and the source and destination regions), the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised.
Examples:
> ```racket
> > ( define s ( string #\A #\p #\p #\l #\e ) )
> > ( string-copy! s 4 "y" )
> > ( string-copy! s 0 s 3 4 )
> > s
> "lpply"
> ```
> ```
(parameter)	→
(-> and/c string? (not/c immutable?))


# 4.3.5 Extflonums
```
Changes dest so that every position in the string is filled with char.

Examples:

> ```racket
> > ( define s ( string #\A #\p #\p #\l #\e ) )
> > ( string-fill! s #\q )
> > s
> "qqqqq"
> ```

> ```
(string-append str ...) → string?
  str : string?```

Returns a new mutable string that is as long as the sum of the given strs’ lengths, and that contains the concatenated characters of the given strs. If no strs are provided, the result is a zero-length string.

Example:

> ```racket
> > ( string-append "Apple" "Banana" )
> "AppleBanana"
> ```

> ```
(string-append-immutable str ...) → (and/c string? immutable?)
  str : string?
```
The same as string-append, but the result is an immutable string.
Examples:
> ```racket
> > ( string-append-immutable "Apple" "Banana" )
> "AppleBanana"
> > ( immutable? ( string-append-immutable "A" "B" ) )
> #t
> ```
Added in version 7.5.0.14 of package base.
> ```
(string  →  list str)   →   (listof char?)
  str : string?```
Returns a new list of characters corresponding to the content of str. That is, the length of the list is ([string-length](#%28def._%28%28quote._~23~25kernel%29._string-length%29%29) str), and the sequence of characters in str is the same sequence in the result list.
Example:
> ```racket
> > ( string->list "Apple" )
> '(#\A #\p #\p #\l #\e)
> ```
> ```
(list  →  string lst)  →  string?
  lst : (listof char?)


# 4.3.5 Extflonums
```
Returns a new mutable string whose content is the list of characters in lst. That is, the length of the string is (length lst), and the sequence of characters in lst is the same sequence in the result string.

Example:

> ```racket
> > ( list  →  string ( list #\A #\p #\p #\l #\e ) )
> "Apple"
> ```

> ```
(build-string n proc)   →   string?
  n : exact-nonnegative-integer?
  proc : (exact-nonnegative-integer? .  →  . char?)```

Creates a string of n characters by applying proc to the integers from 0 to ([sub1](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._sub1%29%29) n) in order. If str is the resulting string, then ([string-ref](#%28def._%28%28quote._~23~25kernel%29._string-ref%29%29) str i) is the character produced by (proc i).

Example:

> ```racket
> > ( build-string 5 ( lambda ( i ) ( integer->char ( + i 97 ) ) ) )
> "abcde"
> ```

#### 4.4.2 String Comparisons

> ```
(string=? str1 str2 ...) → boolean?
  str1 : string?
  str2 : string?
```
Returns #t if all of the arguments are equal?.
Examples:
> ```racket
> > ( string=? "Apple" "apple" )
> #f
> > ( string=? "a" "as" "a" )
> #f
> ```
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
>
<colgroup><col style="width: 100%" /></colgroup>

procedure

(string<? str1 str2 ...)  →  boolean?

  str1 : string?

  str2 : string?


# 4.3.5 Extflonums
Returns #t if the arguments are lexicographically sorted increasing, where individual characters are ordered by char<?, #f otherwise.
Examples:
> ```racket
> > ( string<? "Apple" "apple" )> #t
> > ( string<? "apple" "Apple" )> #f
> > ( string<? "a" "b" "c" )> #t
> ```
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
>
<colgroup><col style="width: 100%" /></colgroup>

procedure

(string<=? str1 str2 ...)  →  boolean?

  str1 : string?

  str2 : string?

Like string<?, but checks whether the arguments are nondecreasing.
Examples:
> ```racket
> > ( string<=? "Apple" "apple" )> #t
> > ( string<=? "apple" "Apple" )> #f
> > ( string<=? "a" "b" "b" )> #t
> ```
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
> ```
(string>? str1 str2 ...) → boolean?
  str1 : string?
  str2 : string?```
Like [string<?](#%28def._%28%28quote._~23~25kernel%29._string~3c~3f%29%29), but checks whether the arguments are decreasing.
Examples:
> ```racket
> > ( string>? "Apple" "apple" )
> #f
> > ( string>? "apple" "Apple" )
> #t
> > ( string>? "c" "b" "a" )
> #t
> ```
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
> ```
(string>=? str1 str2 ...) → boolean?
  str1 : string?
  str2 : string?


# 4.3.5 Extflonums
```
Like string<?, but checks whether the arguments are nonincreasing.

Examples:

> ```racket
> > ( string>=? "Apple" "apple" )
> #f
> > ( string>=? "apple" "Apple" )
> #t
> > ( string>=? "c" "b" "b" )
> #t
> ```

Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.

> ```
(string-ci=? str1 str2 ...) → boolean?
  str1 : string?
  str2 : string?```

Returns #t if all of the arguments are [equal?](Equality.html#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29) after locale-insensitive case-folding via [string-foldcase](#%28def._%28%28quote._~23~25kernel%29._string-foldcase%29%29).

Examples:

> ```racket
> > ( string-ci=? "Apple" "apple" )
> #t
> > ( string-ci=? "a" "a" "a" )
> #t
> ```

Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>procedure</p>

<p>([string-ci<?](#%28def._%28%28quote._~23~25kernel%29._string-ci~3c~3f%29%29) str1 str2 ...) → [boolean?](booleans.html#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29)</p></blockquote></td></tr><tr><td>  str1 : [string?](#%28def._%28%28quote._~23~25kernel%29._string~3f%29%29)</td></tr><tr><td>  str2 : [string?](#%28def._%28%28quote._~23~25kernel%29._string~3f%29%29)</td></tr></tbody></table>

Like [string<?](#%28def._%28%28quote._~23~25kernel%29._string~3c~3f%29%29), but checks whether the arguments would be in increasing order if each was first case-folded using [string-foldcase](#%28def._%28%28quote._~23~25kernel%29._string-foldcase%29%29) (which is locale-insensitive).

Examples:

> ```racket
> > ( string-ci<? "Apple" "apple" )> #f
> > ( string-ci<? "apple" "banana" )> #t
> > ( string-ci<? "a" "b" "c" )> #t
> ```

Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>procedure</p>

<p>([string-ci<=?](#%28def._%28%28quote._~23~25kernel%29._string-ci~3c~3d~3f%29%29) str1 str2 ...) → [boolean?](booleans.html#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29)</p></blockquote></td></tr><tr><td>  str1 : [string?](#%28def._%28%28quote._~23~25kernel%29._string~3f%29%29)</td></tr><tr><td>  str2 : [string?](#%28def._%28%28quote._~23~25kernel%29._string~3f%29%29)</td></tr></tbody></table>

Like [string-ci<?](#%28def._%28%28quote._~23~25kernel%29._string-ci~3c~3f%29%29), but checks whether the arguments would be nondecreasing after case-folding.

Examples:

> ```racket
> > ( string-ci<=? "Apple" "apple" )> #t
> > ( string-ci<=? "apple" "Apple" )> #t
> > ( string-ci<=? "a" "b" "b" )> #t
> ```

Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.

> ```
(string-ci>? str1 str2 ...) → boolean?
  str1 : string?
  str2 : string?
```


# 4.3.5 Extflonums
Like string-ci<?, but checks whether the arguments would be decreasing after case-folding.
Examples:
> ```racket
> > ( string-ci>? "Apple" "apple" )
> #f
> > ( string-ci>? "banana" "Apple" )
> #t
> > ( string-ci>? "c" "b" "a" )
> #t
> ```
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
> ```
(string-ci>=? str1 str2 ...) → boolean?
  str1 : string?
  str2 : string?```
Like [string-ci<?](#%28def._%28%28quote._~23~25kernel%29._string-ci~3c~3f%29%29), but checks whether the arguments would be nonincreasing after case-folding.
Examples:
> ```racket
> > ( string-ci>=? "Apple" "apple" )
> #t
> > ( string-ci>=? "apple" "Apple" )
> #t
> > ( string-ci>=? "c" "b" "b" )
> #t
> ```
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.


#### 4.4.3 String Conversions
> ```
(string-upcase str)  →  string?
  str : string?
```

Returns a string whose characters are the upcase conversion of the characters in str. The conversion uses Unicode’s locale-independent conversion rules that map code-point sequences to code-point sequences (instead of simply mapping a 1-to-1 function on code points over the string), so the string produced by the conversion can be longer than the input string.

Examples:

> ```racket
> > ( string-upcase "abc!" )
> "ABC!"
> > ( string-upcase "Straße" )
> "STRASSE"
> ```

> ```
(string-downcase string)  →  string?
  string : string?
```
Like [string-upcase](#%28def._%28%28quote._~23~25kernel%29._string-upcase%29%29), but the downcase conversion.
Examples:
> ```racket
> > ( string-downcase "aBC!" )
> "abc!"
> > ( string-downcase "Straße" )
> "straße"
> > ( string-downcase "ΚΑΟΣ" )
> "καος"
> > ( string-downcase "Σ" )
> "σ"
> ```
> ```
(string-titlecase string)  →  string?
  string : string?


# 4.3.5 Extflonums
```
Like string-upcase, but the titlecase conversion only for the first character in each sequence of cased characters in str (ignoring case-ignorable characters).

Examples:

> ```racket
> > ( string-titlecase "aBC twO" )
> "Abc Two"
> > ( string-titlecase "y2k" )
> "Y2k"
> > ( string-titlecase "main straße" )
> "Main Straße"
> > ( string-titlecase "stra ße" )
> "Stra Sse"
> ```

> ```
(string-foldcase string)   →   string?
  string : string?```

Like [string-upcase](#%28def._%28%28quote._~23~25kernel%29._string-upcase%29%29), but the case-folding conversion.

Examples:

> ```racket
> > ( string-foldcase "aBC!" )
> "abc!"
> > ( string-foldcase "Straße" )
> "strasse"
> > ( string-foldcase "ΚΑΟΣ" )
> "καοσ"
> ```

> ```
(string-normalize-nfd string)  →  string?
  string : string?
```
Returns a string that is the Unicode normalized form D of string. If the given string is already in the corresponding Unicode normal form, the string may be returned directly as the result (instead of a newly allocated string).
Example:
> ```racket
> > ( equal? ( string-normalize-nfd "Ç" ) "Ç" )
> #t
> ```
> ```
(string-normalize-nfkd string)  →  string?
  string : string?
```

Like [string-normalize-nfd](#%28def._%28%28quote._~23~25kernel%29._string-normalize-nfd%29%29), but for normalized form KD.

Example:

> ```racket
> > ( equal? ( string-normalize-nfkd "ℌ" ) "H" )
> #t
> ```

> ```
(string-normalize-nfc string)  →  string?
  string : string?
```
Like string-normalize-nfd, but for normalized form C.
Example:


# 4.3.5 Extflonums
> ```racket
> > ( equal? ( string-normalize-nfc "Ç" ) "Ç" )
> #t
> ```
> ```
(string-normalize-nfkc string)   →   string?
  string : string?```
Like [string-normalize-nfd](#%28def._%28%28quote._~23~25kernel%29._string-normalize-nfd%29%29), but for normalized form KC.
Example:
> ```racket
> > ( equal? ( string-normalize-nfkc "ℋ̧" ) "Ḩ" )
> #t
> ```


#### 4.4.4 Locale-Specific String Operations
> ```
(string-locale=? str1 str2 ...) → boolean?
  str1 : string?
  str2 : string?
```
(parameter)	→
(-> string-locale>? str1 str2 ...)```

Like [string>?](#%28def._%28%28quote._~23~25kernel%29._string~3e~3f%29%29), but locale-specific like [string-locale<?](#%28def._%28%28quote._~23~25kernel%29._string-locale~3c~3f%29%29).

Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.

> ```
(string-locale-ci=? str1 str2 ...) → boolean?
  str1 : string?
  str2 : string?
```
Like string-locale=?, but strings are compared using rules that are both locale-specific and case-insensitive (depending on what “case-insensitive” means for the current locale).
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>
<p>procedure</p>
<p>(string-locale-ci<? str1 str2 ...)  →  boolean?</p></blockquote></td></tr><tr><td>  str1 : string?</td></tr><tr><td>  str2 : string?</td></tr></tbody></table>
Like string<?, but both locale-sensitive and case-insensitive like string-locale-ci=?.
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
> ```
(string-locale-ci>? str1 str2 ...) → boolean?
  str1 : string?
  str2 : string?```


# 4.3.5 Extflonums
Like [string>?](#%28def._%28%28quote._~23~25kernel%29._string~3e~3f%29%29), but both locale-sensitive and case-insensitive like [string-locale-ci=?](#%28def._%28%28quote._~23~25kernel%29._string-locale-ci~3d~3f%29%29).
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
> ```
(string-locale-upcase string)  →  string?
  string : string?
```
(parameter)	→```

Like [string-downcase](#%28def._%28%28quote._~23~25kernel%29._string-downcase%29%29), but using locale-specific case-conversion rules based on the value of [current-locale](encodings.html#%28def._%28%28quote._~23~25kernel%29._current-locale%29%29).

#### 4.4.5 String Grapheme Clusters

> ```
(string-grapheme-span str start [end) → exact-nonnegative-integer?
  str : string?
  start : exact-nonnegative-integer?
  end : exact-nonnegative-integer? = (string-length str)
```
Returns the number of characters (i.e., code points) in the string that form a Unicode grapheme cluster starting at start, assuming that start is the start of a grapheme cluster and extending no further than the character before end. The result is 0 if start equals end.
The start and end arguments must be valid indices as for substring, otherwise the exn:fail:contract exception is raised.
See also char-grapheme-cluster-step.
Examples:


# 4.3.5 Extflonums
> ```racket
> > ( string-grapheme-span "" 0 )
> 0
> > ( string-grapheme-span "a" 0 )
> 1
> > ( string-grapheme-span "ab" 0 )
> 1
> > ( string-grapheme-span "\r\n" 0 )
> 2
> > ( string-grapheme-span "\r\nx" 0 )
> 2
> > ( string-grapheme-span "\r\nx" 2 )
> 1
> > ( string-grapheme-span "\r\nx" 0 1 )
> 1
> ```
Added in version 8.6.0.2 of package base.
> ```
(string-grapheme-count str start [end)
   →   exact-nonnegative-integer?
  str : string?
  start : exact-nonnegative-integer?
  end : exact-nonnegative-integer? = (string-length str)```
Returns the number of grapheme clusters in ([substring](#%28def._%28%28quote._~23~25kernel%29._substring%29%29) str start end).
The start and end arguments must be valid indices as for [substring](#%28def._%28%28quote._~23~25kernel%29._substring%29%29), otherwise the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised.
Examples:
> ```racket
> > ( string-grapheme-count "" )
> 0
> > ( string-grapheme-count "a" )
> 1
> > ( string-grapheme-count "ab" )
> 2
> > ( string-grapheme-count "ab" 0 2 )
> 2
> > ( string-grapheme-count "ab" 0 1 )
> 1
> > ( string-grapheme-count "\r\n" )
> 1
> > ( string-grapheme-count "a\r\nb" )
> 3
> ```
Added in version 8.6.0.2 of package base.


#### 4.4.6 Additional String Functions
|                                                                                |                                                                                |
|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/string](#%28mod-path._racket%2Fstring%29)) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |
The bindings documented in this section are provided by the [racket/string](#%28mod-path._racket%2Fstring%29) and [racket](index.html) libraries, but not [racket/base](index.html).
> ```
(string-append* str ... strs) → string?
  str : string?
  strs : (listof string?)


# 4.3.5 Extflonums
```
Like string-append, but the last argument is used as a list of arguments for string-append, so (string-append* str ... strs) is the same as (apply string-append str ... strs). In other words, the relationship between string-append and string-append* is similar to the one between list and list*.

Examples:

> ```racket
> > ( string-append* "a" "b" ' ( "c" "d" ) )
> "abcd"
> > ( string-append* ( cdr ( append* ( map ( lambda ( x ) ( list ", " x ) ) ' ( "Alpha" "Beta" "Gamma" ) ) ) ) )
> "Alpha, Beta, Gamma"
> ```

> ```
(string-join strs
   [ sep
    #:before-first before-first
    #:before-last before-last
    #:after-last after-last)    →    string?

  strs : (listof string?)
  sep : string? = " "
  before-first : string? = ""
  before-last : string? = sep
  after-last : string? = ""```

Appends the strings in strs, inserting sep between each pair of strings in strs. before-last, before-first, and after-last are analogous to the inputs of [add-between](pairs.html#%28def._%28%28lib._racket%2Flist..rkt%29._add-between%29%29): they specify an alternate separator between the last two strings, a prefix string, and a suffix string respectively.

Examples:

> ```racket
> > ( string-join ' ( "one" "two" "three" "four" ) )
> "one two three four"
> > ( string-join ' ( "one" "two" "three" "four" ) ", " )
> "one, two, three, four"
> > ( string-join ' ( "one" "two" "three" "four" ) " potato " )
> "one potato two potato three potato four"
> > ( string-join ' ( "x" "y" "z" ) ", " #:before-first "Todo: " #:before-last " and " #:after-last "." )
> "Todo: x, y and z."
> ```

> ```
(string-normalize-spaces str
   [ sep
    space
    #:trim? trim?
    #:repeat? repeat?)    →    string?

  str : string?
  sep : (or/c string? regexp?) = #px"\\s+"
  space : string? = " "
  trim? : any/c = #t
  repeat? : any/c = #f
```


# 4.3.5 Extflonums
Normalizes spaces in the input str by trimming it (using string-trim and sep) and replacing all whitespace sequences in the result with space, which defaults to a single space.
Example:
> ```racket
> > ( string-normalize-spaces " foo bar baz \r\n\t" )
> "foo bar baz"
> ```
The result of (string-normalize-spaces str sep space) is the same as (string-join (string-split str sep ....) space).
> ```
(string-replace str from to [#:all? all?) → string?
  str : string?
  from : (or/c string? regexp?)
  to : string?
  all? : any/c = #t```
Returns str with all occurrences of from replaced with by to. If from is a string, it is matched literally (as opposed to being used as a [regular expression](regexp.html#%28tech._regular._expression%29)).
By default, all occurrences are replaced, but only the first match is replaced if all? is #f.
Example:
> ```racket
> > ( string-replace "foo bar baz" "bar" "blah" )
> "foo blah baz"
> ```
> ```
(string-split str
   [ sep
    #:trim? trim?
    #:repeat? repeat?)    →    (listof string?)
  str : string?
  sep : (or/c string? regexp?) = #px"\\s+"
  trim? : any/c = #t
  repeat? : any/c = #f


# 4.3.5 Extflonums
```
Splits the input str on sep, returning a list of substrings of str that are separated by sep, defaulting to splitting the input on whitespaces. The input is first trimmed using sep (see string-trim), unless trim? is #f. Empty matches are handled in the same way as for regexp-split. As a special case, if str is the empty string after trimming, the result is '() instead of '("").

Like string-trim, provide sep to use a different separator, and repeat? controls matching repeated sequences.

Examples:

> ```racket
> > ( string-split " foo bar baz \r\n\t" )
> '("foo" "bar" "baz")
> > ( string-split " " )
> '()
> > ( string-split " " #:trim? #f )
> '("" "")
> ```

> ```
(string-trim str
   [ sep
    #:left? left?
    #:right? right?
    #:repeat? repeat?)    →    string?

  str : string?
  sep : (or/c string? regexp?) = #px"\\s+"
  left? : any/c = #t
  right? : any/c = #t
  repeat? : any/c = #f```

Trims the input str by removing prefix and suffix sep, which defaults to whitespace. A string sep is matched literally (as opposed to being used as a [regular expression](regexp.html#%28tech._regular._expression%29)).

Use #:left? #f or #:right? #f to suppress trimming the corresponding side. When repeat? is #f (the default), only one match is removed from each side; when repeat? is true, all initial or trailing matches are trimmed (which is an alternative to using a [regular expression](regexp.html#%28tech._regular._expression%29) sep that contains +).

Examples:

> ```racket
> > ( string-trim " foo bar baz \r\n\t" )
> "foo bar baz"
> > ( string-trim " foo bar baz \r\n\t" " " #:repeat? #t )
> "foo bar baz \r\n\t"
> > ( string-trim "aaaxaayaa" "aa" )
> "axaay"
> ```

> ```
(non-empty-string? x)  →  boolean?
  x : any/c
```


# 4.3.5 Extflonums
Returns #t if x is a string and is not empty; returns #f otherwise.
Added in version 6.3 of package base.
> ```
(string-find s contained)  →  (or/c exact-nonnegative-integer? #f)
  s : string?
  contained : string?
(string-contains? s contained)  →  boolean?
  s : string?
  contained : string?
(string-prefix? s prefix)  →  boolean?
  s : string?
  prefix : string?
(string-suffix? s suffix)  →  boolean?
  s : string?
  suffix : string?
```

Checks whether s includes at any location, starts with, or ends with the second argument, respectively. The [string-find](#%28def._%28%28lib._racket%2Fstring..rkt%29._string-find%29%29) function returns the first position within s where contained is found, if any, while [string-contains?](#%28def._%28%28lib._racket%2Fstring..rkt%29._string-contains~3f%29%29) reports only whether it was found.

Examples:

> ```racket
> > ( string-prefix? "Racket" "R" )
> #t
> > ( string-prefix? "Jacket" "R" )
> #f
> > ( string-suffix? "Racket" "et" )
> #t
> > ( string-find "Racket" "ack" )
> 1
> > ( string-contains? "Racket" "ack" )
> #t
> ```

Added in version 6.3 of package base.
Changed in version 8.15.0.7: Added [string-find](#%28def._%28%28lib._racket%2Fstring..rkt%29._string-find%29%29).

#### 4.4.7 Converting Values to Strings

|                                                                                |                                                                                |
|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/format](#%28mod-path._racket%2Fformat%29)) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |

The bindings documented in this section are provided by the [racket/format](#%28mod-path._racket%2Fformat%29) and [racket](index.html) libraries, but not [racket/base](index.html).

The [racket/format](#%28mod-path._racket%2Fformat%29) library provides functions for converting Racket values to strings. In addition to features like padding and numeric formatting, the functions have the virtue of being shorter than [format](Writing.html#%28def._%28%28quote._~23~25kernel%29._format%29%29) (with format string), [number->string](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._number-~3estring%29%29), or [string-append](#%28def._%28%28quote._~23~25kernel%29._string-append%29%29).

> ```
(~a   v
    ...
   [ #:separator separator
    #:width width
    #:max-width max-width
    #:min-width min-width
    #:limit-marker limit-marker
    #:limit-prefix? limit-prefix?
    #:align align
    #:pad-string pad-string
    #:left-pad-string left-pad-string
    #:right-pad-string right-pad-string)    →    string?

  v : any/c
  separator : string? = ""
  width : (or/c exact-nonnegative-integer? #f) = #f
   max-width   :   (or/c exact-nonnegative-integer? +inf.0)
      =   (or width +inf.0)

  min-width : exact-nonnegative-integer? = (or width 0)
  limit-marker : string? = ""
  limit-prefix? : boolean? = #f
  align : (or/c 'left 'center 'right) = 'left
  pad-string : non-empty-string? = " "
  left-pad-string : non-empty-string? = pad-string
  right-pad-string : non-empty-string? = pad-string
```