POV-Ray : Newsgroups : povray.newusers : scientific notation : Re: scientific notation Server Time
3 Oct 2025 04:17:26 EDT (-0400)
  Re: scientific notation  
From: Kenneth
Date: 24 Sep 2025 11:40:00
Message: <web.68d41047f4db7ec9e83955656e066e29@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
>
> Try using floor().  Or ceil.  Or maybe POV-Ray does weird things and you
> need to test your value and then conditionally use one or the other.
>

FIXED for fractional values, by using floor:

---------
#macro SciNot (Num, Precision)
#if (Num = 0)
#local Result = "0\n"
#else
#local Exponent = int(floor(log(abs(Num))));
#local Significand = Num/pow(10, Exponent);
#local Result = concat (str(Significand, 0, Precision), "e", str(Exponent, 0,
0), "\n")
#end
#debug Result
#end
---------

Example:
#declare MY_VAL = -.00674;

// the macro:
SciNot (MY_VAL, 3)

returns  -6.740e-3

-----------
BTW, this will also work:
#local Exponent = int(log(#if(Num < 1 & Num > -1) .1* #else #end abs(Num)));


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.