File: maxima_13.html

package info (click to toggle)
maxima 5.47.0-9
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 193,104 kB
  • sloc: lisp: 434,678; fortran: 14,665; tcl: 10,990; sh: 4,577; makefile: 2,763; ansic: 447; java: 328; python: 262; perl: 201; xml: 60; awk: 28; sed: 15; javascript: 2
file content (854 lines) | stat: -rw-r--r-- 39,874 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Maxima 5.47.0 Manual: Functions and Variables for Numbers</title>

<meta name="description" content="Maxima 5.47.0 Manual: Functions and Variables for Numbers">
<meta name="keywords" content="Maxima 5.47.0 Manual: Functions and Variables for Numbers">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="maxima_toc.html#Top" rel="start" title="Top">
<link href="maxima_423.html#Function-and-Variable-Index" rel="index" title="Function and Variable Index">
<link href="maxima_toc.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="maxima_11.html#Numbers" rel="up" title="Numbers">
<link href="maxima_14.html#Strings" rel="next" title="Strings">
<link href="maxima_12.html#Introduction-to-Numbers" rel="previous" title="Introduction to Numbers">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
body {color: black; background: white;  margin-left: 8%; margin-right: 13%;
      font-family: "FreeSans", sans-serif}
h1 {font-size: 150%; font-family: "FreeSans", sans-serif}
h2 {font-size: 125%; font-family: "FreeSans", sans-serif}
h3 {font-size: 100%; font-family: "FreeSans", sans-serif}
a[href] {color: rgb(0,0,255); text-decoration: none;}
a[href]:hover {background: rgb(220,220,220);}
div.textbox {border: solid; border-width: thin; padding-top: 1em;
    padding-bottom: 1em; padding-left: 2em; padding-right: 2em}
div.titlebox {border: none; padding-top: 1em; padding-bottom: 1em;
    padding-left: 2em; padding-right: 2em; background: rgb(200,255,255);
    font-family: sans-serif}
div.synopsisbox {
    border: none; padding-top: 1em; padding-bottom: 1em; padding-left: 2em;
    padding-right: 2em; background: rgb(255,220,255);}
pre.example {border: 1px solid rgb(180,180,180); padding-top: 1em;
    padding-bottom: 1em; padding-left: 1em; padding-right: 1em;
    background-color: rgb(238,238,255)}
div.spacerbox {border: none; padding-top: 2em; padding-bottom: 2em}
div.image {margin: 0; padding: 1em; text-align: center}
div.categorybox {border: 1px solid gray; padding-top: 1em; padding-bottom: 1em;
    padding-left: 1em; padding-right: 1em; background: rgb(247,242,220)}
img {max-width:80%; max-height: 80%; display: block; margin-left: auto; margin-right: auto}

-->
</style>

<link rel="icon" href="figures/favicon.ico">
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6>"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Functions-and-Variables-for-Numbers"></a>
<div class="header">
<p>
Previous: <a href="maxima_12.html#Introduction-to-Numbers" accesskey="p" rel="previous">Introduction to Numbers</a>, Up: <a href="maxima_11.html#Numbers" accesskey="u" rel="up">Numbers</a> &nbsp; [<a href="maxima_toc.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="maxima_423.html#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Functions-and-Variables-for-Numbers-1"></a>
<h4 class="subsection">5.1.2 Functions and Variables for Numbers</h4>

<a name="bfloat"></a><a name="Item_003a-DataTypes_002fdeffn_002fbfloat"></a><dl>
<dt><a name="index-bfloat"></a>Function: <strong>bfloat</strong> <em>(<var>expr</var>)</em></dt>
<dd>
<p><code>bfloat</code> replaces integers, rationals, floating point numbers, and some symbolic constants
in <var>expr</var> with bigfloat (variable-precision floating point) numbers.
</p>
<p>The constants <code>%e</code>, <code>%gamma</code>, <code>%phi</code>, and <code>%pi</code>
are replaced by a numerical approximation.
However, <code>%e</code> in <code>%e^x</code> is not replaced by a numeric value
unless <code>bfloat(x)</code> is a number.
</p>
<p><code>bfloat</code> also causes numerical evaluation of some built-in functions,
namely trigonometric functions, exponential functions, <code>abs</code>, and <code>log</code>.
</p>
<p>The number of significant digits in the resulting bigfloats is specified by the
global variable <code><a href="#fpprec">fpprec</a></code>.
Bigfloats already present in <var>expr</var> are replaced with values which have
precision specified by the current value of <code><a href="#fpprec">fpprec</a></code>.
</p>
<p>When <code><a href="#float2bf">float2bf</a></code> is <code>false</code>, a warning message is printed when
a floating point number is replaced by a bigfloat number with less precision.
</p>
<p>Examples:
</p>
<p><code>bfloat</code> replaces integers, rationals, floating point numbers, and some symbolic constants
in <var>expr</var> with bigfloat numbers.
</p>
<div class="example">
<pre class="example">(%i1) bfloat([123, 17/29, 1.75]);
(%o1)        [1.23b2, 5.862068965517241b-1, 1.75b0]
(%i2) bfloat([%e, %gamma, %phi, %pi]);
(%o2) [2.718281828459045b0, 5.772156649015329b-1, 
                        1.618033988749895b0, 3.141592653589793b0]
(%i3) bfloat((f(123) + g(h(17/29)))/(x + %gamma));
         1.0b0 (g(h(5.862068965517241b-1)) + f(1.23b2))
(%o3)    ----------------------------------------------
                    x + 5.772156649015329b-1
</pre></div>

<p><code>bfloat</code> also causes numerical evaluation of some built-in functions.
</p>
<div class="example">
<pre class="example">(%i1) bfloat(sin(17/29));
(%o1)                 5.532051841609784b-1
(%i2) bfloat(exp(%pi));
(%o2)                  2.314069263277927b1
(%i3) bfloat(abs(-%gamma));
(%o3)                 5.772156649015329b-1
(%i4) bfloat(log(%phi));
(%o4)                 4.812118250596035b-1
</pre></div>

<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="bfloatp"></a><a name="Item_003a-DataTypes_002fdeffn_002fbfloatp"></a><dl>
<dt><a name="index-bfloatp"></a>Function: <strong>bfloatp</strong> <em>(<var>expr</var>)</em></dt>
<dd>
<p>Returns <code>true</code> if <var>expr</var> is a bigfloat number, otherwise <code>false</code>.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;<a href="maxima_424.html#Category_003a-Predicate-functions">Predicate functions</a>
&middot;</div></dd></dl>

<a name="bftorat"></a><a name="Item_003a-DataTypes_002fdefvr_002fbftorat"></a><dl>
<dt><a name="index-bftorat"></a>Option variable: <strong>bftorat</strong></dt>
<dd><p>Default value: <code>false</code>
</p>
<p><code>bftorat</code> controls the conversion of bfloats to rational numbers.  When
<code>bftorat</code> is <code>false</code>, <code><a href="#ratepsilon">ratepsilon</a></code> will be used to control the
conversion (this results in relatively small rational numbers).  When
<code>bftorat</code> is <code>true</code>, the rational number generated will accurately
represent the bfloat.
</p>
<p>Note: <code>bftorat</code> has no effect on the transformation to rational numbers
with the function <code><a href="#rationalize">rationalize</a></code>.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">(%i1) ratepsilon:1e-4;
(%o1)                         1.0e-4
(%i2) rat(bfloat(11111/111111)), bftorat:false;
`rat' replaced 9.99990999991B-2 by 1/10 = 1.0B-1
                               1
(%o2)/R/                       --
                               10
(%i3) rat(bfloat(11111/111111)), bftorat:true;
`rat' replaced 9.99990999991B-2 by 11111/111111 = 9.99990999991B-2
                             11111
(%o3)/R/                     ------
                             111111
</pre></div>

<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="bftrunc"></a><a name="Item_003a-DataTypes_002fdefvr_002fbftrunc"></a><dl>
<dt><a name="index-bftrunc"></a>Option variable: <strong>bftrunc</strong></dt>
<dd><p>Default value: <code>true</code>
</p>
<p><code>bftrunc</code> causes trailing zeroes in non-zero bigfloat numbers not to be
displayed.  Thus, if <code>bftrunc</code> is <code>false</code>, <code>bfloat (1)</code>
displays as <code>1.000000000000000B0</code>.  Otherwise, this is displayed as
<code>1.0B0</code>.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="bigfloat_005fbits"></a><a name="Item_003a-DataTypes_002fdeffn_002fbigfloat_005fbits"></a><dl>
<dt><a name="index-bigfloat_005fbits"></a>Function: <strong>bigfloat_bits</strong> <em>()</em></dt>
<dd><p>Returns the number of bits of precision in a bigfloat number.  This
value depends, of course, on the value of <code><a href="#fpprec">fpprec</a></code>. 
</p>
<div class="example">
<pre class="example">(%i1) fpprec:16;
(%o1)                                 16
(%i2) bigfloat_bits();
(%o2)                                 56
(%i3) fpprec:32;
(%o3)                                 32
(%i4) bigfloat_bits();
(%o4)                                 109
</pre></div>

<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="bigfloat_005feps"></a><a name="Item_003a-DataTypes_002fdeffn_002fbigfloat_005feps"></a><dl>
<dt><a name="index-bigfloat_005feps"></a>Function: <strong>bigfloat_eps</strong> <em>()</em></dt>
<dd><p>Returns the smallest bigfloat value, <code>eps</code>, such that
<code>1+eps</code> is not equal to 1.  The value depends on <code><a href="#fpprec">fpprec</a></code>,
of course.
</p>
<div class="example">
<pre class="example">(%i1) fpprec:16;
(%o1)                                 16
(%i2) bigfloat_eps();
(%o2)                        1.387778780781446b-17
(%i3) fpprec:32;
(%o3)                                 32
(%i4) bigfloat_eps();
(%o4)                1.5407439555097886824447823540679b-33
</pre></div>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="decode_005ffloat"></a><a name="Item_003a-DataTypes_002fdeffn_002fdecode_005ffloat"></a><dl>
<dt><a name="index-decode_005ffloat"></a>Function: <strong>decode_float</strong> <em>(<var>f</var>)</em></dt>
<dd><p><code>decode_float</code> takes a float <var>f</var> and returns a list of three
values that characterizes <var>f</var>, which must be either a <code>float</code>
or <code>bfloat</code>.  The first value has the same type as <var>f</var>, but
is a number in the range <code>[1, 2)</code>.  The second value is an
exponent.  The third value is a float of the same type as <var>f</var> and
has the value of 1 if <var>f</var> is greater than or equal to 0;
otherwise, -1.
</p>
<p>If the returned list is <code>[mantissa, expo, sign]</code>, then
<code>scale_float(mantissa, exp)*sign</code> is identical to <var>f</var>.
</p>
<div class="example">
<pre class="example">(%i1) decode_float(4e0);
(%o1)                            [1.0, 2, 1.0]
(%i2) decode_float(4b0);
(%o2)                          [1.0b0, 2, 1.0b0]
(%i3) decode_float(%pi);

decode_float is only defined for floats and bfloats: %pi
 -- an error. To debug this try: debugmode(true);
(%i4) decode_float(float(%pi));
(%o4)                     [1.570796326794897, 1, 1.0]
(%i5) decode_float(1.1e-5);
(%o5)                        [1.441792, - 17, 1.0]
(%i6) %[1]*2^%[2];
(%o6)                               1.1e-5
</pre></div>

<p>This is a relatively simple interface to Common Lisp
<a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_dec_fl.htm">decode_float</a>.  However we return a signficand in the range
<code>[1,2)</code> instead of <code>[0.5, 1)</code>.  The former matches
IEEE-754.  Of course, this is extended to support bfloats.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="evenp"></a><a name="Item_003a-DataTypes_002fdeffn_002fevenp"></a><dl>
<dt><a name="index-evenp"></a>Function: <strong>evenp</strong> <em>(<var>expr</var>)</em></dt>
<dd>
<p>Returns <code>true</code> if <var>expr</var> is a literal even integer, otherwise
<code>false</code>.
</p>
<p><code>evenp</code> returns <code>false</code> if <var>expr</var> is a symbol, even if <var>expr</var>
is declared <code>even</code>.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Predicate-functions">Predicate functions</a>
&middot;</div></dd></dl>

<a name="float"></a><a name="Item_003a-DataTypes_002fdeffn_002ffloat"></a><dl>
<dt><a name="index-float"></a>Function: <strong>float</strong> <em>(<var>expr</var>)</em></dt>
<dd>
<p>Converts integers, rational numbers and bigfloats in <var>expr</var> to floating
point numbers.  It is also an <code><a href="maxima_43.html#evflag">evflag</a></code>, <code>float</code> causes
non-integral rational numbers and bigfloat numbers to be converted to floating
point.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;<a href="maxima_424.html#Category_003a-Evaluation-flags">Evaluation flags</a>
&middot;</div></dd></dl>

<a name="float2bf"></a><a name="Item_003a-DataTypes_002fdefvr_002ffloat2bf"></a><dl>
<dt><a name="index-float2bf"></a>Option variable: <strong>float2bf</strong></dt>
<dd><p>Default value: <code>true</code>
</p> 
<p>When <code><a href="#float2bf">float2bf</a></code> is <code>false</code>, a warning message is printed when
a floating point number is replaced by a bigfloat number with less precision.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="float_005fbits"></a><a name="Item_003a-DataTypes_002fdeffn_002ffloat_005fbits"></a><dl>
<dt><a name="index-float_005fbits"></a>Function: <strong>float_bits</strong> <em>()</em></dt>
<dd><p>Returns the number of bits of precision of a floating-point number.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="float_005feps"></a><a name="Item_003a-DataTypes_002fdeffn_002ffloat_005feps"></a><dl>
<dt><a name="index-float_005feps"></a>Function: <strong>float_eps</strong> <em>()</em></dt>
<dd><p>Returns the smallest floating-point value, <code>eps</code>, such that
<code>1+eps</code> is not equal to 1.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="float_005fprecision"></a><a name="Item_003a-DataTypes_002fdeffn_002ffloat_005fprecision"></a><dl>
<dt><a name="index-float_005fprecision"></a>Function: <strong>float_precision</strong> <em>(<var>f</var>)</em></dt>
<dd><p>Returns the number of bits of precision of a floating-point number,
which can be either a float or bigfloat.  This is basically the number
of bits used to represent the mantissa of a floating-point number.
For floats, this is 53 (for IEEE double-floats), but can be less when
denormal numbers occur.  For bigfloats, this is equal to
<code><a href="#fpprec">fpprec</a></code>, when converted from digits to bits.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="floatnump"></a><a name="Item_003a-DataTypes_002fdeffn_002ffloatnump"></a><dl>
<dt><a name="index-floatnump"></a>Function: <strong>floatnump</strong> <em>(<var>expr</var>)</em></dt>
<dd>
<p>Returns <code>true</code> if <var>expr</var> is a floating point number, otherwise
<code>false</code>.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;<a href="maxima_424.html#Category_003a-Predicate-functions">Predicate functions</a>
&middot;</div></dd></dl>

<a name="fpprec"></a><a name="Item_003a-DataTypes_002fdefvr_002ffpprec"></a><dl>
<dt><a name="index-fpprec"></a>Option variable: <strong>fpprec</strong></dt>
<dd><p>Default value: 16
</p>
<p><code>fpprec</code> is the number of significant digits for arithmetic on bigfloat
numbers.  <code>fpprec</code> does not affect computations on ordinary floating point
numbers.
</p>
<p>See also <code><a href="#bfloat">bfloat</a></code> and <code><a href="#fpprintprec">fpprintprec</a></code>.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="fpprintprec"></a><a name="Item_003a-DataTypes_002fdefvr_002ffpprintprec"></a><dl>
<dt><a name="index-fpprintprec"></a>Option variable: <strong>fpprintprec</strong></dt>
<dd><p>Default value: 0
</p>
<p><code>fpprintprec</code> is the number of digits to print when printing an ordinary
float or bigfloat number.
</p>
<p>For ordinary floating point numbers,
when <code>fpprintprec</code> has a value between 2 and 16 (inclusive),
the number of digits printed is equal to <code>fpprintprec</code>.
Otherwise, <code>fpprintprec</code> is 0, or greater than 16,
and the number is printed &quot;readably&quot;:
that is, it is printed with sufficient digits to exactly reconstruct the number on input.
</p>
<p>For bigfloat numbers,
when <code>fpprintprec</code> has a value between 2 and <code>fpprec</code> (inclusive),
the number of digits printed is equal to <code>fpprintprec</code>.
Otherwise, <code>fpprintprec</code> is 0, or greater than <code>fpprec</code>,
and the number of digits printed is equal to <code>fpprec</code>.
</p>
<p>For both ordinary floats and bigfloats,
trailing zero digits are suppressed.
The actual number of digits printed is less than <code>fpprintprec</code>
if there are trailing zero digits.
</p>
<p><code>fpprintprec</code> cannot be 1.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;<a href="maxima_424.html#Category_003a-Display-flags-and-variables">Display flags and variables</a>
&middot;</div></dd></dl>

<a name="integerp"></a><a name="Item_003a-DataTypes_002fdeffn_002fintegerp"></a><dl>
<dt><a name="index-integerp"></a>Function: <strong>integerp</strong> <em>(<var>expr</var>)</em></dt>
<dd>
<p>Returns <code>true</code> if <var>expr</var> is a literal numeric integer, otherwise
<code>false</code>.
</p>
<p><code>integerp</code> returns <code>false</code> if <var>expr</var> is a symbol, even if <var>expr</var>
is declared <code>integer</code>.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">(%i1) integerp (0);
(%o1)                         true
(%i2) integerp (1);
(%o2)                         true
(%i3) integerp (-17);
(%o3)                         true
(%i4) integerp (0.0);
(%o4)                         false
(%i5) integerp (1.0);
(%o5)                         false
(%i6) integerp (%pi);
(%o6)                         false
(%i7) integerp (n);
(%o7)                         false
(%i8) declare (n, integer);
(%o8)                         done
(%i9) integerp (n);
(%o9)                         false
</pre></div>

<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Predicate-functions">Predicate functions</a>
&middot;</div></dd></dl>

<a name="integer_005fdecode_005ffloat"></a><a name="Item_003a-DataTypes_002fdeffn_002finteger_005fdecode_005ffloat"></a><dl>
<dt><a name="index-integer_005fdecode_005ffloat"></a>Function: <strong>integer_decode_float</strong> <em>(<var>f</var>)</em></dt>
<dd><p><code>integer_decode_float</code> takes a float <var>f</var> and returns a list of three
values that characterizes <var>f</var>, which must be either a <code>float</code>
or <code>bfloat</code>.  The first value is an integer.  The second value is an
exponent.  The third value is 1 if <var>f</var> is positive or zero;
otherwise, -1.
</p>
<p>If the returned list is <code>[mantissa, expo, sign]</code>, then
<code>scale_float(fl(mantissa), expo)*sign</code> is identical to <var>f</var>.
Here, <code>fl</code> is either <code>float</code> or <code>bfloat</code> depending on
whether <var>f</var> is a <code>float</code> or a <code>bfloat</code>.
</p>
<div class="example">
<pre class="example">(%i1) integer_decode_float(4.0);
(%o1)                     [4503599627370496, - 50, 1]
(%i2) integer_decode_float(4b0);
(%o2)                    [36028797018963968, - 53, 1]
(%i3) scale_float(float(%o1[1]), %o1[2]);
(%o3)                                 4.0
(%i4) scale_float(bfloat(%o2[1]), %o2[2]);
(%o4)                                4.0b0
(%i5) integer_decode_float(4);

decode_float is only defined for floats and bfloats: 4
 -- an error. To debug this try: debugmode(true);
(%i6) integer_decode_float(1e-7);
(%o6)                     [7555786372591432, - 76, 1]
(%i7) integer_decode_float(1b-7);
(%o7)                    [60446290980731459, - 79, 1]
(%i8) scale_float(float(%o6[1]), %o6[2]);
(%o8)                               1.0e-7
</pre></div>

<p>For lisps that support denormal numbers, we have the following results.
</p><div class="example">
<pre class="example">(%i1) integer_decode_float(least_positive_float);
(%o1)                           [1, - 1074, 1]
(%i2) integer_decode_float(100*least_positive_float);
(%o2)                          [100, - 1074, 1]
(%i3) integer_decode_float(least_positive_normalized_float);
(%o3)                    [4503599627370496, - 1074, 1]
</pre></div>
<p>The number of bits in the integer part decreases as the denormal
number decreases.  Bfloat numbers do not have denormals because the
exponent is not bounded.
</p>
<p>This is a relatively simple interface to Common Lisp
<a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_dec_fl.htm">integer_decode_float</a>.  However, the integer part can vary depending
on the Lisp implementation; we return the same value, independent of
the Lisp implementation.  Of course, this is extended to support bfloats.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="is_005fpower_005fof_005ftwo"></a><a name="Item_003a-DataTypes_002fdeffn_002fis_005fpower_005fof_005ftwo"></a><dl>
<dt><a name="index-is_005fpower_005fof_005ftwo"></a>Function: <strong>is_power_of_two</strong> <em>(<var>n</var>)</em></dt>
<dd><p><code>is_power_to_two</code> returns <code>true</code> if <var>n</var> is a power of
two and <code>false</code> otherwise.  <var>n</var> may be an integer, a
rational, a float, or a big float.
</p>
<p>Some examples:
</p><div class="example">
<pre class="example">(%i1) is_power_of_two(0);
(%o1)                                false
(%i2) is_power_of_two(4);
(%o2)                                true
(%i3) is_power_of_two(355/113);
(%o3)                                false
(%i4) is_power_of_two(1/32);
(%o4)                                true
(%i5) is_power_of_two(1048576);
(%o5)                                true
(%i6) is_power_of_two(1048575);
(%o6)                                false
(%i7) is_power_of_two(0.0);
(%o7)                                false
(%i8) is_power_of_two(1048576.0);
(%o8)                                true
(%i9) is_power_of_two(1048575.0);
(%o9)                                false
(%i10) is_power_of_two(1/256.0);
(%o10)                               true
(%i11) is_power_of_two(0b0);
(%o11)                               false
(%i12) is_power_of_two(1048576b0);
(%o12)                               true
(%i13) is_power_of_two(1048575b0);
(%o13)                               false
(%i14) is_power_of_two(1/256b0);
(%o14)                               true
</pre></div>

<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Predicate-functions">Predicate functions</a>
&middot;</div></dd></dl>

<a name="m1pbranch"></a><a name="Item_003a-DataTypes_002fdefvr_002fm1pbranch"></a><dl>
<dt><a name="index-m1pbranch"></a>Option variable: <strong>m1pbranch</strong></dt>
<dd><p>Default value: <code>false</code>
</p>
<p><code>m1pbranch</code> is the principal branch for <code>-1</code> to a power.
Quantities such as <code>(-1)^(1/3)</code> (that is, an &quot;odd&quot; rational exponent) and 
<code>(-1)^(1/4)</code> (that is, an &quot;even&quot; rational exponent) are handled as follows:
</p>
<div class="example">
<pre class="example">              domain:real
                            
(-1)^(1/3):      -1         
(-1)^(1/4):   (-1)^(1/4)   

             domain:complex              
m1pbranch:false          m1pbranch:true
(-1)^(1/3)               1/2+%i*sqrt(3)/2
(-1)^(1/4)              sqrt(2)/2+%i*sqrt(2)/2
</pre></div>

<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Expressions">Expressions</a>
&middot;<a href="maxima_424.html#Category_003a-Global-flags">Global flags</a>
&middot;</div></dd></dl>

<a name="nonnegintegerp"></a><a name="Item_003a-DataTypes_002fdeffn_002fnonnegintegerp"></a><dl>
<dt><a name="index-nonnegintegerp"></a>Function: <strong>nonnegintegerp</strong> <em>(<var>n</var>)</em></dt>
<dd>
<p>Return <code>true</code> if and only if <code><var>n</var> &gt;= 0</code> and <var>n</var> is an integer.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Predicate-functions">Predicate functions</a>
&middot;</div></dd></dl>

<a name="numberp"></a><a name="Item_003a-DataTypes_002fdeffn_002fnumberp"></a><dl>
<dt><a name="index-numberp"></a>Function: <strong>numberp</strong> <em>(<var>expr</var>)</em></dt>
<dd>
<p>Returns <code>true</code> if <var>expr</var> is a literal integer, rational number, 
floating point number, or bigfloat, otherwise <code>false</code>.
</p>
<p><code>numberp</code> returns <code>false</code> if <var>expr</var> is a symbol, even if <var>expr</var>
is a symbolic number such as <code>%pi</code> or <code>%i</code>, or declared to be
<code>even</code>, <code>odd</code>, <code>integer</code>, <code>rational</code>, <code>irrational</code>,
<code>real</code>, <code>imaginary</code>, or <code>complex</code>.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">(%i1) numberp (42);
(%o1)                         true
(%i2) numberp (-13/19);
(%o2)                         true
(%i3) numberp (3.14159);
(%o3)                         true
(%i4) numberp (-1729b-4);
(%o4)                         true
(%i5) map (numberp, [%e, %pi, %i, %phi, inf, minf]);
(%o5)      [false, false, false, false, false, false]
(%i6) declare (a, even, b, odd, c, integer, d, rational,
     e, irrational, f, real, g, imaginary, h, complex);
(%o6)                         done
(%i7) map (numberp, [a, b, c, d, e, f, g, h]);
(%o7) [false, false, false, false, false, false, false, false]
</pre></div>

<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Predicate-functions">Predicate functions</a>
&middot;</div></dd></dl>


<a name="numer"></a><a name="Item_003a-DataTypes_002fdefvr_002fnumer"></a><dl>
<dt><a name="index-numer"></a>Option variable: <strong>numer</strong></dt>
<dd>
<p><code>numer</code> causes some mathematical functions (including exponentiation)
with numerical arguments to be evaluated in floating point.  It causes
variables in <code>expr</code> which have been given numerals to be replaced by
their values.  It also sets the <code><a href="#float">float</a></code> switch on.
</p>
<p>See also <code><a href="maxima_51.html#g_t_0025enumer">%enumer</a></code>.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">(%i1) [sqrt(2), sin(1), 1/(1+sqrt(3))];
                                        1
(%o1)            [sqrt(2), sin(1), -----------]
                                   sqrt(3) + 1
</pre><pre class="example">(%i2) [sqrt(2), sin(1), 1/(1+sqrt(3))],numer;
(%o2) [1.414213562373095, 0.8414709848078965, 0.3660254037844387]
</pre></div>

<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;<a href="maxima_424.html#Category_003a-Evaluation-flags">Evaluation flags</a>
&middot;</div></dd></dl>

<a name="numer_005fpbranch"></a><a name="Item_003a-DataTypes_002fdefvr_002fnumer_005fpbranch"></a><dl>
<dt><a name="index-numer_005fpbranch"></a>Option variable: <strong>numer_pbranch</strong></dt>
<dd><p>Default value: <code>false</code>
</p>
<p>The option variable <code>numer_pbranch</code> controls the numerical evaluation of 
the power of a negative integer, rational, or floating point number.  When
<code>numer_pbranch</code> is <code>true</code> and the exponent is a floating point number
or the option variable <code><a href="#numer">numer</a></code> is <code>true</code> too, Maxima evaluates
the numerical result using the principal branch.  Otherwise a simplified, but
not an evaluated result is returned.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">(%i1) (-2)^0.75;
                                 0.75
(%o1)                       (- 2)
</pre><pre class="example">(%i2) (-2)^0.75,numer_pbranch:true;
(%o2)       1.189207115002721 %i - 1.189207115002721
</pre><pre class="example">(%i3) (-2)^(3/4);
                               3/4  3/4
(%o3)                     (- 1)    2
</pre><pre class="example">(%i4) (-2)^(3/4),numer;
                                          0.75
(%o4)              1.681792830507429 (- 1)
</pre><pre class="example">(%i5) (-2)^(3/4),numer,numer_pbranch:true;
(%o5)       1.189207115002721 %i - 1.189207115002721
</pre></div>

<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>


<a name="numerval"></a><a name="Item_003a-DataTypes_002fdeffn_002fnumerval"></a><dl>
<dt><a name="index-numerval"></a>Function: <strong>numerval</strong> <em>(<var>x_1</var>, <var>expr_1</var>, &hellip;, <var>var_n</var>, <var>expr_n</var>)</em></dt>
<dd>
<p>Declares the variables <code>x_1</code>, &hellip;, <var>x_n</var> to have
numeric values equal to <code>expr_1</code>, &hellip;, <code>expr_n</code>.
The numeric value is evaluated and substituted for the variable
in any expressions in which the variable occurs if the <code>numer</code> flag is
<code>true</code>.  See also <code><a href="maxima_43.html#ev">ev</a></code>.
</p>
<p>The expressions <code>expr_1</code>, &hellip;, <code>expr_n</code> can be any expressions,
not necessarily numeric.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Declarations-and-inferences">Declarations and inferences</a>
&middot;<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="oddp"></a><a name="Item_003a-DataTypes_002fdeffn_002foddp"></a><dl>
<dt><a name="index-oddp"></a>Function: <strong>oddp</strong> <em>(<var>expr</var>)</em></dt>
<dd>
<p>Returns <code>true</code> if <var>expr</var> is a literal odd integer, otherwise
<code>false</code>.
</p>
<p><code>oddp</code> returns <code>false</code> if <var>expr</var> is a symbol, even if <var>expr</var>
is declared <code>odd</code>.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Predicate-functions">Predicate functions</a>
&middot;</div></dd></dl>

<a name="ratepsilon"></a><a name="Item_003a-DataTypes_002fdefvr_002fratepsilon"></a><dl>
<dt><a name="index-ratepsilon"></a>Option variable: <strong>ratepsilon</strong></dt>
<dd><p>Default value: <code>2.0e-15</code>
</p>
<p><code>ratepsilon</code> is the tolerance used in the conversion
of floating point numbers to rational numbers, when the option variable
<code><a href="#bftorat">bftorat</a></code> has the value <code>false</code>.  See <code>bftorat</code> for an example.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;<a href="maxima_424.html#Category_003a-Rational-expressions">Rational expressions</a>
&middot;</div></dd></dl>

<a name="rationalize"></a><a name="Item_003a-DataTypes_002fdeffn_002frationalize"></a><dl>
<dt><a name="index-rationalize"></a>Function: <strong>rationalize</strong> <em>(<var>expr</var>)</em></dt>
<dd>
<p>Convert all double floats and big floats in the Maxima expression <var>expr</var> to
their exact rational equivalents.  If you are not familiar with the binary
representation of floating point numbers, you might be surprised that
<code>rationalize (0.1)</code> does not equal 1/10.  This behavior isn&rsquo;t special to
Maxima &ndash; the number 1/10 has a repeating, not a terminating, binary
representation.
</p>
<div class="example">
<pre class="example">(%i1) rationalize (0.5);
                                1
(%o1)                           -
                                2
</pre><pre class="example">(%i2) rationalize (0.1);
                        3602879701896397
(%o2)                   -----------------
                        36028797018963968
</pre><pre class="example">(%i3) fpprec : 5$
</pre><pre class="example">(%i4) rationalize (0.1b0);
                             209715
(%o4)                        -------
                             2097152
</pre><pre class="example">(%i5) fpprec : 20$
</pre><pre class="example">(%i6) rationalize (0.1b0);
                     236118324143482260685
(%o6)                ----------------------
                     2361183241434822606848
</pre><pre class="example">(%i7) rationalize (sin (0.1*x + 5.6));
               3602879701896397 x   3152519739159347
(%o7)      sin(------------------ + ----------------)
               36028797018963968    562949953421312
</pre></div>

<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div></dd></dl>

<a name="ratnump"></a><a name="Item_003a-DataTypes_002fdeffn_002fratnump"></a><dl>
<dt><a name="index-ratnump"></a>Function: <strong>ratnump</strong> <em>(<var>expr</var>)</em></dt>
<dd>
<p>Returns <code>true</code> if <var>expr</var> is a literal integer or ratio of literal
integers, otherwise <code>false</code>.
</p>
<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Predicate-functions">Predicate functions</a>
&middot;<a href="maxima_424.html#Category_003a-Rational-expressions">Rational expressions</a>
&middot;</div></dd></dl>

<a name="scale_005ffloat"></a><a name="Item_003a-DataTypes_002fdeffn_002fscale_005ffloat"></a><dl>
<dt><a name="index-scale_005ffloat"></a>Function: <strong>scale_float</strong> <em>(<var>f</var>, <var>n</var>)</em></dt>
<dd><p><code>scale_float</code> scales the float <var>f</var> by the value
<code>2^<var>n</var></code>.  This is done carefully so that no round-off every
occurs.  If <var>f</var> is a float, then it is possible to underflow to 0
or overflow, depending on the value of <var>f</var> and <var>n</var>.  Bigfloats
cannot underflow or overflow.
</p>
<div class="example">
<pre class="example">(%i1) scale_float(2d0, 2);
(%o1)                                 8.0
(%i2) scale_float(2d0, -2);
(%o2)                                 0.5
(%i3) scale_float(-2d0, -10);
(%o3)                            - 0.001953125
(%i4) scale_float(1d0, -2000);
(%o4)                                 0.0
(%i5) scale_float(2b0, 2);
(%o5)                                8.0b0
(%i6) scale_float(1b0, -2000);
(%o6)                       8.709809816217217b-603
(%i7) scale_float(1, 5);

scale_float: first arg must be a float or bfloat: 1
 -- an error. To debug this try: debugmode(true);
(%i8) scale_float(1.0, n);

scale_float: second arg must be an integer: n
 -- an error. To debug this try: debugmode(true);
</pre></div>

<p>This is a relatively simple interface to Common Lisp
<a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_dec_fl.htm">scale_float</a>.  Of course, this is extended to support bfloats.
</p>
</dd></dl>

<a name="unit_005fin_005flast_005fplace"></a><a name="Item_003a-DataTypes_002fdeffn_002funit_005fin_005flast_005fplase"></a><dl>
<dt><a name="index-unit_005fin_005flast_005fplase"></a>Function: <strong>unit_in_last_plase</strong> <em>(<var>n</var>)</em></dt>
<dd>
<p><code>unit_in_last_place</code> returns a value that is the gap between
<var>n</var> and the nearest other number.  See, for example,
<a href="https://people.eecs.berkeley.edu/~wkahan/LOG10HAF.TXT">Kahan, FOOTNOTE 1</a>.  <code>unit_in_last_place</code> supports rational numbers,
floating-point numbers and bigfloat numbers.  For integer, the result
is always 1, and for rational numbers the result is always 0.
</p>
<p>The examples below assume
<a href="https://en.wikipedia.org/wiki/IEEE_754">IEEE-754</a> arithmetic that
supports
<a href="https://en.wikipedia.org/wiki/IEEE_754-1985#Denormalized_numbers">denormal</a>
numbers.  Some lisps like <a href="https://clisp.sourceforge.io/">Clisp</a>
do not have denormal numbers.
</p>
<div class="example">
<pre class="example">(%i1) unit_in_last_place(0);
(%o1)                                  1
(%i2) unit_in_last_place(-123);
(%o2)                                  1
(%i3) unit_in_last_place(2/3);
(%o3)                                  0
(%i4) unit_in_last_place(355/113);
(%o4)                                  0
(%i5) unit_in_last_place(0b0);
(%o5)                                0.0b0
(%i6) unit_in_last_place(0.0);
(%o6)                       4.940656458412465e-324
(%i7) unit_in_last_place(1.0);
(%o7)                        1.110223024625157e-16
(%i8) unit_in_last_place(1b0);
(%o8)                        1.387778780781446b-17
(%i9) unit_in_last_place(100.0);
(%o9)                         1.4210854715202e-14
(%i10) unit_in_last_place(100b0);
(%o10)                       1.77635683940025b-15
(%i11) fpprec:32;
(%o11)                                32
(%i12) unit_in_last_place(1b0);
(%o12)               1.5407439555097886824447823540679b-33
(%i13) unit_in_last_place(100b0);
(%o13)               1.972152263052529513529321413207b-31
</pre></div>

<div class=categorybox>
Categories:<a href="maxima_424.html#Category_003a-Numerical-evaluation">Numerical evaluation</a>
&middot;</div>
</dd></dl>

<a name="Item_003a-DataTypes_002fnode_002fStrings"></a><hr>
<div class="header">
<p>
Previous: <a href="maxima_12.html#Introduction-to-Numbers" accesskey="p" rel="previous">Introduction to Numbers</a>, Up: <a href="maxima_11.html#Numbers" accesskey="u" rel="up">Numbers</a> &nbsp; [<a href="maxima_toc.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="maxima_423.html#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>