## Name:

rationalmode global variable controlling if rational arithmetic is used or not.

## Library names:

void sollya_lib_set_rationalmode_and_print(sollya_obj_t) void sollya_lib_set_rationalmode(sollya_obj_t) sollya_obj_t sollya_lib_get_rationalmode()

## Usage:

rationalmode = activation value : on|off -> void rationalmode = activation value ! : on|off -> void rationalmode : on|off

## Parameters:

• activation value controls if rational arithmetic should be used or not

## Description:

• rationalmode is a global variable. When its value is off, which is the default, Sollya will not use rational arithmetic to simplify expressions. All computations, including the evaluation of constant expressions given on the Sollya prompt, will be performed using floating-point and interval arithmetic. Constant expressions will be approximated by floating-point numbers, which are in most cases faithful roundings of the expressions, when shown at the prompt.
• When the value of the global variable rationalmode is on, Sollya will use rational arithmetic when simplifying expressions. Constant expressions, given at the Sollya prompt, will be simplified to rational numbers and displayed as such when they are in the set of the rational numbers. Otherwise, floating-point and interval arithmetic will be used to compute a floating-point approximation, which is in most cases a faithful rounding of the constant expression.
• When a decimal value is parsed, the behavior of Sollya is different depending on the value of the global variable rationalmode. If it is off, the value gets rounded as a floating-point at precision prec. But if rationalmode is set to on, the decimal value is interpreted exactly and converted as a rational number of the form M/10^N where M and N are integers. Accordingly, when rationalmode is set to on and display is set to decimal, all floating-point values are displayed exactly: indeed, any floating-point number with radix 2 has a finite decimal expansion. Therefore, any rational number of the form M/(2^P*5^Q) gets displayed as an exact decimal value (while other fractions get displayed as fractions).

## Example 1:

> rationalmode=off!;
> 19/17 + 3/94;
1.1495619524405506883604505632040050062578222778473
> rationalmode=on!;
> 19/17 + 3/94;
1837 / 1598

## Example 2:

> rationalmode=off!;
> exp(19/17 + 3/94);
3.1568097739551413675470920894482427634032816281442
> rationalmode=on!;
> exp(19/17 + 3/94);
3.1568097739551413675470920894482427634032816281441796574919218482279430946893345552216426846046106958476007343642301414070837350944742638603202067315578460693359375

## Example 3:

> prec = 12!;
> rationalmode=off!;
> r = 0.1;
> r == 1/10;
false
> rationalmode=on!;
> s = 0.1;
> s == 1/10;
true
> r == s;
false
> r;
0.100006103515625
> s;
0.1
See also: on, off, numerator, denominator, simplify, rationalapprox, autosimplify
Go back to the list of commands